加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

dart – Flutter:设置AppBar的高度

发布时间:2020-12-14 14:49:43 所属栏目:百科 来源:网络整理
导读:如何在Flutter中设置AppBar的高度? 栏的标题应该垂直居中(在那个AppBar中). 解决方法 在撰写本文时,我不知道PreferredSize. Cinn的答案更好地实现了这一目标. 您可以使用自定义高度创建自己的自定义小部件: import "package:flutter/material.dart";class
如何在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),),);
  }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读