程序入口和Theme

StatelessWidget和StatefulWidget
class MyApp extends StatelessWidget {
// This widget is the root of your application.这是我的APP的基底
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.deepOrange,
),
home: MyHomePage(
title: 'Flutter Demo Home Page'),
);
}
}
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,
textAlign: TextAlign.right,
maxLines: 1,
overflow: TextOverflow.fade,
style: TextStyle(
fontSize: 40,
color: Colors.white,
decoration: TextDecoration.underline,
decorationStyle: TextDecorationStyle.wavy,
),
),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text.rich(TextSpan(children: [
TextSpan(
text: "You know who\n ",
style: TextStyle(
color: Colors.green,
fontSize: 34,
)),
TextSpan(text: " have pushed the button this many times:,")
])),
Text(
'$_counter',//变化数据的使用
style: Theme
.of(context)
.textTheme
.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,//这里就是点击事件的触发
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
使用资源包
站在巨人肩膀上:https://pub.dartlang.org
427

被折叠的 条评论
为什么被折叠?



