Flutter Widget框架

  • 现代响应式框架
  • 主要用于构建UI
  • 根据状态渲染(当widget的状态发生变化时,widget会重新构建UI,Flutter会对比前后变化的不同, 以确定底层渲染树从一个状态转换到下一个状态所需的最小更改(译者语:类似于React/Vue中虚拟DOM的diff算法)
  • 编写一个MyAppBar
/**
 * 创建一个自定义的AppBar
 */
class MyAppBar extends StatelessWidget {

  /**
   * 构建方法
   */
  MyAppBar({this.title});

  final Widget title; // title属性 一般用final来标记

  @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]),
      // Row 是水平方向的线性布局(linear layout)
      child: new Row(
        //列表项的类型是 <Widget>
        children: <Widget>[
          new IconButton(
            icon: new Icon(Icons.menu),
            tooltip: 'Navigation menu',
            onPressed: null, // null 会禁用 button
          ),
          // Expanded expands its child to fill the available space.
          new Expanded(
            child: title,
          ),
          new IconButton(
            icon: new Icon(Icons.search),
            tooltip: 'Search',
            onPressed: null,
          ),
        ],
      ),
    );
  }

}
  • 编写一个MyScaffold
/**
 * 自定义内容
 */
class MyScaffold extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    // Material是UI呈现的一张白纸
    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!'),))
          
//          new Expanded(
//            child: new Center(
//              child: new Text('Hello, world!'),
//            ),
//          ),

        ],
      ),
    );
  }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值