微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

dart – Flutter:设置AppBar的高度

如何在Flutter中设置AppBar的高度?

栏的标题应该垂直居中(在那个AppBar中).

解决方法

在撰写本文时,我不知道PreferredSize. Cinn的答案更好地实现了这一目标.

您可以使用自定义高度创建自己的自定义小部件:

import "package:Flutter/material.dart";

class Page extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Column(children : <Widget>[new CustomAppBar("Custom App Bar"),new Container()],);
  }
}


class CustomAppBar extends StatelessWidget {

  final String title;
  final double barHeight = 50.0; // change this for different heights 

  CustomAppBar(this.title);

  @override
  Widget build(BuildContext context) {
    final double statusbarHeight = MediaQuery
        .of(context)
        .padding
        .top;

    return new Container(
      padding: new EdgeInsets.only(top: statusbarHeight),height: statusbarHeight + barHeight,child: new Center(
        child: new Text(
          title,style: new TextStyle(fontSize: 20.0,fontWeight: FontWeight.bold),),);
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐