Flutter底部不规则导航的实现过程
程序员文章站
2022-09-06 13:38:44
前言
本文主要介绍的是关于flutter实现底部不规则导航的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧
实现方法:
1、main.dar...
前言
本文主要介绍的是关于flutter实现底部不规则导航的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧
实现方法:
1、main.dart文件
import 'package:flutter/material.dart'; import 'bootom_appbar.dart'; void main () =>runapp(myapp()); class myapp extends statelesswidget { @override widget build(buildcontext context) { return materialapp( title:'不规则底部导航', //自定义主题样本 theme:themedata( primaryswatch:colors.lightblue ), home:bottomappbardemo(), ); } }
2、bootom_appbar.dart
import 'package:flutter/material.dart'; import 'each_view.dart'; class bottomappbardemo extends statefulwidget { @override _bottomappbardemostate createstate() => _bottomappbardemostate(); } class _bottomappbardemostate extends state<bottomappbardemo> { list<widget> _eachview; int _index = 0; @override void initstate() { _eachview = list(); _eachview ..add(eachview('主页的页面')); _eachview ..add(eachview('副页的页面')); // todo: implement initstate super.initstate(); } @override widget build(buildcontext context) { return scaffold( //变换页面 body: _eachview[_index], floatingactionbutton: floatingactionbutton( onpressed: (){ navigator.of(context).push(materialpageroute(builder: (buildcontext context){ return eachview('新添加的页面'); })); }, tooltip: '添加', child: icon( icons.add, color: colors.white, ), ), floatingactionbuttonlocation: floatingactionbuttonlocation.centerdocked, bottomnavigationbar: bottomappbar( //工具栏比navigationbar灵活 color: colors.lightblue, //与fab融合 //圆形缺口 shape: circularnotchedrectangle(), child: row( mainaxissize: mainaxissize.max, mainaxisalignment: mainaxisalignment.spacearound, children: <widget>[ iconbutton( icon: icon(icons.home), color: colors.white, onpressed: (){ setstate(() { _index = 0; }); }, ), iconbutton( icon: icon(icons.airport_shuttle), color: colors.white, onpressed: (){ setstate(() { _index = 1; }); }, ) ], ), ), ); } }
3、each_view.dart
import 'package:flutter/material.dart'; class eachview extends statefulwidget { string _title; eachview(this._title); @override _eachviewstate createstate() => _eachviewstate(); } class _eachviewstate extends state<eachview> { @override widget build(buildcontext context) { return scaffold( appbar: appbar(title: text(widget._title),), body: center(child: text(widget._title),), ); } }
4、效果展示
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。