I just got started with Dart/Flutter and my goal is to execute the default flutter app template generated with the flutter --create
command in VS Code
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter ;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
But whenever I try to run it, I get this series of errors from several files in the Material library and I can't find out what is causing them or how to solve them.
: Error: Not found: 'dart:ui'
../…/material/animated_icons.dart:9
import 'dart:ui' as ui show Paint, Path, Canvas;
^
: Error: Not found: 'dart:ui'
../…/material/animated_icons.dart:10
import 'dart:ui' show lerpDouble;
^
: Error: Not found: 'dart:ui'
../…/material/app.dart:5
import 'dart:ui' as ui;
^
: Error: Not found: 'dart:ui'
../…/material/app_bar_theme.dart:5
import 'dart:ui' show lerpDouble;
^
: Error: Not found: 'dart:ui'
../…/material/arc.dart:6
import 'dart:ui' show lerpDouble;
^
: Error: Not found: 'dart:ui'
../…/material/bottom_app_bar_theme.dart:5
import 'dart:ui' show lerpDouble;
^
: Error: Not found: 'dart:ui'
../…/material/bottom_navigation_bar_theme.dart:5
import 'dart:ui' show lerpDouble;
^
: Error: Not found: 'dart:ui'
../…/material/bottom_sheet.dart:5
import 'dart:ui' show lerpDouble;
^
: Error: Not found: 'dart:ui'
../…/material/bottom_sheet_theme.dart:5
import 'dart:ui' show lerpDouble;
^
: Error: Not found: 'dart:ui'
../…/material/button_bar_theme.dart:5
import 'dart:ui' show lerpDouble;
^
Running plain Dart projects like the one created with dart create -t console-full dart_application_1 --force: running
works fine.
Can anyone tell me what causes this error?
CodePudding user response:
Are you using flutter run in terminal or you are using your ide for running main.dart file.
first try flutter run --debug
or use your ide with the flutter icon not the simple one for running main function .
CodePudding user response:
Make sure you are in the correct directory or file and not the parent folder.