- 现代响应式框架
- 主要用于构建UI
- 根据状态渲染(当widget的状态发生变化时,widget会重新构建UI,Flutter会对比前后变化的不同, 以确定底层渲染树从一个状态转换到下一个状态所需的最小更改(译者语:类似于React/Vue中虚拟DOM的diff算法)
- 编写一个MyAppBar
class MyAppBar extends StatelessWidget {
MyAppBar({this.title});
final Widget title;
@override
Widget build(BuildContext context) {
return new Container(
height: 86.0,
padding: const EdgeInsets.fromLTRB(8.0,40.0,8.0,0.0),
decoration: new BoxDecoration(color: Colors.blue[500]),
child: new Row(
children: <Widget>[
new IconButton(
icon: new Icon(Icons.menu),
tooltip: 'Navigation menu',
onPressed: null,
),
new Expanded(
child: title,
),
new IconButton(
icon: new Icon(Icons.search),
tooltip: 'Search',
onPressed: null,
),
],
),
);
}
}
class MyScaffold extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Material(
child: new Column(
children: <Widget>[
new MyAppBar(
title: new Text(
'Example title', style: Theme.of(context).primaryTextTheme.title,
),
),
new Expanded(child: new Center(child: new Text('Hello, world!'),))
],
),
);
}
}