flutter学习七 flutter自定义顶部导航按钮

Flutter AppBar 自定义顶部按钮图标、颜色

属性描述
leading在标题前面显示的一个控件,在首页通常显示应用 的 logo;在其他界面通常显示为返回按钮
title标题,通常显示为当前界面的标题文字,可以放组 件
actions通常使用 IconButton 来表示,可以放按钮组
bottom通常放 tabBar,标题下面显示一个 Tab 导航栏
backgroundColor导航背景颜色
iconTheme图标样式
textTheme文字样式
centerTitle标题是否居中显示
return Scaffold(
      appBar: AppBar(
        title: Text('search page'),
//左侧图标
        // leading: IconButton(
        //   icon: Icon(Icons.menu),
        // ),
         //	右侧图标
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.menu),
          )
        ],
      ),
    );

自定义 TabBar 实 现顶部 Tab 切换

属性描述
tabs显示的标签内容,一般使用 Tab 对象,也可以是其他 的 Widget controller TabController 对象
controllerTabController 对象
isScrollable是否可滚动
indicatorColor指示器颜色
indicatorWeight指示器高度
indicatorPadding底部指示器的 Padding
indicator指示器 decoration,例如边框等
indicatorSize指示器大小计算方式,TabBarIndicatorSize.label 跟文 字等宽,TabBarIndicatorSize.tab 跟每个 tab 等宽
labelColor选中 label 颜色
labelStyle选中 label 的 Style
labelPadding每个 label 的 padding 值
unselectedLabelColor未选中 label 颜色
unselectedLabelStyle未选中 label 的 Style
return DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            title: Text('xxx'),
            bottom: TabBar(
              tabs: <Widget>[
                Tab(text: '热门'),
                Tab(text: '推荐'),
              ],
            )
          ),
          body: TabBarView(
            children: <Widget>[
              ListView(
                children: <Widget>[
                  ListTile(title: Text('腾讯被骗,全网来嘲!')),
                  ListTile(title: Text('乘风破浪的姐姐')),
                ],
              ),
              ListView(
                children: <Widget>[
                  ListTile(title: Text('印度又搞事')),
                ],
              )
            ],
          ),
        ),
      );

当点击需求发请求,事件监听的时候,另一种方法;

import 'package:flutter/material.dart';

class FromPage extends StatefulWidget {
  FromPage({Key key}):super(key: key);
  _FromPageState createState() => _FromPageState();
}

class _FromPageState extends State<FromPage> with SingleTickerProviderStateMixin {
  TabController _tabController;
  @override
  void initState() {//生命周期函数
    super.initState();
    _tabController = new TabController(length: 2, vsync: this);
    _tabController.addListener((){//事件监听
      print(_tabController.index);
    });
  }
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('title'),
        bottom: new TabBar(
          tabs: <Widget>[
            new Tab(text: '推荐'),
            new Tab(text: '热卖')
          ],
          controller: _tabController,
        )
      ),
      body: new TabBarView(
        controller: _tabController,
        children: <Widget>[
          new Center(child:Text('推荐')),
          new Center(child:Text('热卖')),
        ]
      ),
    );
  }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值