资料
1、中文官网:安装和环境配置 | Flutter 中文文档 - Flutter 中文开发者网站 - Flutter
2、线上编写网站:DartPad
构建第一个Flutter应用
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => MyAppState(),
child: MaterialApp(
title: 'hello flutter',
theme: ThemeData(
useMaterial3: true, // 报错
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange), // 报错
),
home: MyHomePage(),
),
);
}
}
问题1:The named parameter 'useMaterial3' isn't defined.
问题原因:跟Flutter的版本有关,此时并未引入Material 3特性,无法使用,想要使用,需升级Flutter,同时Flutter3.16之后,已默认设置useMaterial3为true,也并不需要显示设置
解决方案:
1、基于此版本的Flutter,去掉此设置
2、升级Flutter版本
问题2:The method 'fromSeed' isn't defined for the type 'ColorScheme'.
问题原因:跟问题1出现的原因本质是相同的,ColorScheme.fromSeed
是创建基于Material 3颜色系统的颜色方案的首选方式,因为Flutter版本低,继而无法使用
解决方案:
1、基于此版本的Flutter,需要手动写一个ColorScheme
2、升级Flutter版本