Flutter实现底部导航栏
程序员文章站
2022-03-08 17:14:59
本文实例为大家分享了flutter实现底部导航栏的具体代码,供大家参考,具体内容如下
效果
实现
先将自动生成的main.dart里面的代码删除,...
本文实例为大家分享了flutter实现底部导航栏的具体代码,供大家参考,具体内容如下
效果
实现
先将自动生成的main.dart里面的代码删除,
import 'package:flutter/material.dart'; import 'package:flutter_guohe/pages/main.dart'; void main() { runapp(new guohe()); }
创建app.dart作为首页的页面文件
class guohe extends statefulwidget { @override guohestate createstate() => new guohestate(); } class guohestate extends state<guohe> { @override widget build(buildcontext context) { } }
创建today.dart、kb.dart、playground.dart三个页面文件作为tabview的填充文件,这里用playground.dart为例。
import 'package:flutter/material.dart'; class playground extends statefulwidget { @override playgroundstate createstate() => new playgroundstate(); } class playgroundstate extends state<playground> { @override widget build(buildcontext context) { return new materialapp( home: new scaffold( appbar: new appbar( title: new text("操场"), backgroundcolor: color.fromargb(255, 119, 136, 213), //设置appbar背景颜色 centertitle: true, //设置标题是否局中 ), body: new center( child: new text('操场'), ), ), ); } }
app.dart的完整代码
/** * app的主入口文件 */ import 'package:flutter/material.dart'; import 'package:flutter_guohe/pages/main/today.dart'; import 'package:flutter_guohe/pages/main/playground.dart'; import 'package:flutter_guohe/pages/main/kb.dart'; import 'package:flutter_guohe/pages/main/leftmenu.dart'; import 'package:flutter_guohe/common/eventbus.dart'; //果核的主界面 class guohe extends statefulwidget { @override guohestate createstate() => new guohestate(); } class guohestate extends state<guohe> with singletickerproviderstatemixin { tabcontroller controller; @override void initstate() { controller = new tabcontroller(length: 3, vsync: this); } @override void dispose() { controller.dispose(); super.dispose(); } @override widget build(buildcontext context) { return new materialapp( home: new scaffold( drawer: new leftmenu(), body: new tabbarview( controller: controller, children: <widget>[ new today(), new kb(), new playground(), ], ), bottomnavigationbar: new material( color: colors.white, child: new tabbar( controller: controller, labelcolor: colors.deeppurpleaccent, unselectedlabelcolor: colors.black26, tabs: <widget>[ new tab( text: "今日", icon: new icon(icons.brightness_5), ), new tab( text: "课表", icon: new icon(icons.map), ), new tab( text: "操场", icon: new icon(icons.directions_run), ), ], ), ), ), ); } }
其中
labelcolor: colors.deeppurpleaccent, unselectedlabelcolor: colors.black26,
第一个属性是控制标签颜色,这里我选了紫色,第二个属性是未选中标签时的颜色。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: 那些你不知道的Mac截屏功能
下一篇: Python破解网站登录密码脚本