Unable to import flutter dart file.intelliJ environment

Asked 2 years ago, Updated 2 years ago, 161 views

When I try to execute the code below, I get an error that the file cannot be imported.
I have passed the path to flutter and dart, but do I need any other settings?It would be very helpful if you could let me know.

[Pass]
flutter
dart

[Code]


import 'package:flutter/material.dart';

void main() = > runApp(MyApp());

class MyApp extensions StatelessWidget {
  @override
  Widget build (BuildContext context) {
    US>return MaterialApp(
      title: 'Welcome to Flutter',
      home —Scaffold(
        appBar —AppBar(
          title:Text('Welcome to Flutter'),
        ),
        body: Center(
          child:Text('Hello World'),
        ),
      ),
    );
  }
}

[Error Contents]


Error: Could not resolve the package 'flutter' in 'package:flutter/material.dart'.
main.dart:1:8:Error: Not found: 'package:flutter/material.dart'
import 'package:flutter/material.dart';
       ^
main.dart:7:16:Error: Type 'BuildContext' not found.
  Widget build (BuildContext context) {
               ^^^^^^^^^^^^
main.dart:7:3:Error: Type 'Widget' not found.
  Widget build (BuildContext context) {
  ^^^^^^
main.dart:5:21:Error: Type 'StatelessWidget' not found.
class MyApp extensions StatelessWidget {
                    ^^^^^^^^^^^^^^^
main.dart:3:16:Error: Method not found: 'runApp'.
void main() = > runApp(MyApp());
               ^^^^^^
main.dart:7:16:Error: 'BuildContext' isn't a type.
  Widget build (BuildContext context) {
               ^^^^^^^^^^^^
main.dart:12:18:Error: Method not found: 'Text'.
          title:Text('Welcome to Flutter'),
                 ^^^^
main.dart:11:17:Error:Method not found: 'AppBar'.
        appBar —AppBar(
                ^^^^^^
main.dart:15:18:Error: Method not found: 'Text'.
          child:Text('Hello World'),

intellij-idea

2022-09-29 22:20

1 Answers

I received a solution proposal via teratail.
https://teratail.com/questions/182461

flutter packages get

Resolved by rerunning

Note: Flutter Official Documentation
https://flutter.dev/docs/development/packages-and-packing-packing #packing


2022-09-29 22:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.