flutter 入门AppBar titleSpacing

AppBar 显示在app的顶部。AppBar包含5大部分,如下图:

leading左上角的控件,一般放一个icon,位置如上图
title标题,位置如上图
actions一系列的组件,位置如上图
flexibleSpace此小组件堆叠在工具栏和标签栏后面。它的高度与应用栏的整体高度相同
bottom位置如上图
elevation阴影Z轴
backgroundColor背景颜色
brightness亮度
iconTheme图标样式(用于应用栏图标的颜色,不透明度和大小。通常,这与backgroundColorbrightnesstextTheme一起设置。)
textTheme字体样式
centerTitletitle是否显示在中间
automaticallyImplyLeading如果为true且leading为null,则自动尝试推断出主要小部件应该是什么。如果为false且leading为null,则为title提供前导空格。如果leading小部件不为null,则此参数无效。
toolbarOpacity应用栏的工具栏部分是多么不透明。
bottomOpacity应用栏底部的不透明程度。
primarytrue 此应用栏是否显示在屏幕顶部。
titleSpacing横轴上标题内容 周围的间距。即使没有前导内容或操作,也会应用此间距。如果希望 title占用所有可用空间,请将此值设置为0.0

相关属性代码展示以及运行UI效果展示如下:

import 'package:flutter/material.dart';

//void main() {
//  runApp(
//    new Center(
//      child: new Text(
//        'Hello, world!',
//        textDirection: TextDirection.ltr,
//      ),
//    ),
//  );
//}

class MyAppBar extends StatelessWidget {
  MyAppBar({this.title});

  final Widget title;

  @override
  Widget build(BuildContext context) {
    return new Container(
      height: 56.0, //在逻辑像素中
      padding: const EdgeInsets.symmetric(horizontal: 8.0),
      decoration: new BoxDecoration(color: Colors.blue[500]),
      //Row是水平线性布局。
      child: new Row(
        children: <Widget>[
          new IconButton(
            icon: new Icon(Icons.menu),
            tooltip: 'Navigation menu',
            onPressed: null, // null禁用按钮
          ),
          // Expanded扩展其子项以填充可用空间。
          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(
      // Column 是垂直的线性布局
      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!'),
            ),
          ),
        ],
      ),
    );
  }
}

void main() {
  runApp(new MaterialApp(
    title: 'My app',
    home: new Scaffold(
      appBar: new AppBar(
        leading: new Builder(
          builder: (BuildContext context) {
            return new IconButton(
              icon: const Icon(Icons.menu),
              onPressed: () { Scaffold.of(context).openDrawer(); },
              tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
            );
          },
        ),
        iconTheme: new IconThemeData(color: Colors.red[500]),
        backgroundColor: Colors.black,
        automaticallyImplyLeading: false,
        title: new Text('首页'),
        centerTitle: true,
        actions: <Widget>[
          new IconButton(
            icon: new Icon(Icons.menu,color: Colors.white,),
            tooltip: 'Navigation menu',
            onPressed: null, // null禁用按钮

          ),
          // Expanded扩展其子项以填充可用空间。

          new IconButton(
            icon: new Icon(Icons.search,color: Colors.redAccent,),
            tooltip: 'Search',
            onPressed: null,
          ),
        ],
      ),
      body: new MyAppBar(
        title: new Text('xxxx'),
      ),
    ),
  ));
}

 

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值