MaterialAPP 组件
一般作为顶层的跟组件使用,常用属性有 home title color theme routes 等
更换主题颜色
| MaterialApp( theme: ThemeData(primarySwatch:Colors.red) ) |
Scaffold 组件
相当于声明页面的组件,主要组件有
- appBar 显示顶部的 AppBar
- drawer 抽屉菜单空间
- body 主要内容 widget
- …
| Scaffold( appBar:AppBar(title:Text("标题")), drawer:Drawer(), body:Text("hello flutter") ) |
状态组件
- StatelessWidget 无状态组件
- StatefulWidget 有状态组件,持有生命周期函数,如果数据变化更新视图层,需要使用有状态组件
实现一个 Hello Wrold
| main(){ runApp(MaterialApp( home:MyApp() )) } class MyApp extends StatefulWidget { const MyApp({super.key}); @override State<MyApp> createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title:const Text("hello world") ), ); } } |