Flutter实现底部导航
本文实例为大家分享了Flutter实现底部导航的具体代码,供大家参考,具体内容如下
定州ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18980820575(备注:SSL证书合作)期待与您的合作!
BottomNavigationBar使用
底部导航栏 主文件 main.dart (注意导入文件路径)
import 'package:flutter/material.dart'; import './views/firstPage.dart'; import './views/secondPage.dart'; import './views/thirdPage.dart'; //首先导入三个界面 void main() { runApp(new MyApp()); } class MyApp extends StatefulWidget { @override _MyHomePageState createState() => new _MyHomePageState(); } class _MyHomePageState extends Statewith TickerProviderStateMixin{ int _tabIndex = 0; List _navigationViews; var appBarTitles = ['首页', '发现', '我的']; PageController pageController; var _body; initData() { _body = new IndexedStack( children: [new FirstPage(), new SecondPage(), new ThirdPage()], index: _tabIndex, ); } @override void initState() { super.initState(); _navigationViews = [ new BottomNavigationBarItem( icon: const Icon(Icons.home), title: new Text(appBarTitles[0]), backgroundColor: Colors.blue, ), new BottomNavigationBarItem( icon: const Icon(Icons.widgets), title: new Text(appBarTitles[1]), backgroundColor: Colors.blue, ), new BottomNavigationBarItem( icon: const Icon(Icons.person), title: new Text(appBarTitles[2]), backgroundColor: Colors.blue, ), ]; } final navigatorKey = GlobalKey (); @override Widget build(BuildContext context) { initData(); return new MaterialApp( navigatorKey: navigatorKey, theme: new ThemeData( primaryColor: Colors.blue, accentColor: Colors.blue ), home: new Scaffold( appBar: new AppBar( title: new Text( appBarTitles[_tabIndex], style: new TextStyle(color: Colors.white), ), ), body: _body, bottomNavigationBar: new BottomNavigationBar( items: _navigationViews .map((BottomNavigationBarItem navigationView) => navigationView) .toList(), currentIndex: _tabIndex, type: BottomNavigationBarType.fixed, onTap: (index) { setState(() { _tabIndex = index; }); }, ), ), ); } }
底部包含三个导航按钮,分别对应三个界面:
firstPage.dart
import 'package:flutter/material.dart'; class FirstPage extends StatefulWidget { @override StatecreateState() => new FirstPageState(); } class FirstPageState extends State { @override Widget build(BuildContext context) { return new Scaffold( body: new Center( child: new Text('这是第一个界面'), ), ); } }
secondPage.dart
import 'package:flutter/material.dart'; class SecondPage extends StatefulWidget { @override StatecreateState() => SecondPageState(); } class SecondPageState extends State { @override Widget build(BuildContext context) { return new Scaffold( body: new Center( child: new Text("这是我第二个页面"), ), ); } }
thirdPage.dart
import 'package:flutter/material.dart'; class ThirdPage extends StatefulWidget { @override StatecreateState() => ThirdPageState(); } class ThirdPageState extends State { @override Widget build(BuildContext context) { return new Scaffold( body: new Center( child: new Text('我是界面三'), ), ); } }
运行截图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。
当前文章:Flutter实现底部导航
转载来源:http://azwzsj.com/article/pcdpdi.html