Flutter實(shí)現(xiàn)底部導(dǎo)航
本文實(shí)例為大家分享了Flutter實(shí)現(xiàn)底部導(dǎo)航的具體代碼,供大家參考,具體內(nèi)容如下
BottomNavigationBar使用
底部導(dǎo)航欄 主文件 main.dart (注意導(dǎo)入文件路徑)
import 'package:flutter/material.dart'; import './views/firstPage.dart'; import './views/secondPage.dart'; import './views/thirdPage.dart'; //首先導(dǎo)入三個界面 void main() { runApp(new MyApp()); } class MyApp extends StatefulWidget { @override _MyHomePageState createState() => new _MyHomePageState(); } class _MyHomePageState extends State<MyApp> with TickerProviderStateMixin{ int _tabIndex = 0; List<BottomNavigationBarItem> _navigationViews; var appBarTitles = ['首頁', '發(fā)現(xiàn)', '我的']; PageController pageController; var _body; initData() { _body = new IndexedStack( children: <Widget>[new FirstPage(), new SecondPage(), new ThirdPage()], index: _tabIndex, ); } @override void initState() { super.initState(); _navigationViews = <BottomNavigationBarItem>[ 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<NavigatorState>(); @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; }); }, ), ), ); } }
底部包含三個導(dǎo)航按鈕,分別對應(yīng)三個界面:
firstPage.dart
import 'package:flutter/material.dart'; class FirstPage extends StatefulWidget { @override State<StatefulWidget> createState() => new FirstPageState(); } class FirstPageState extends State<FirstPage> { @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 State<StatefulWidget> createState() => SecondPageState(); } class SecondPageState extends State<SecondPage> { @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 State<StatefulWidget> createState() => ThirdPageState(); } class ThirdPageState extends State<ThirdPage>{ @override Widget build(BuildContext context) { return new Scaffold( body: new Center( child: new Text('我是界面三'), ), ); } }
運(yùn)行截圖:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- flutter實(shí)現(xiàn)更新彈窗內(nèi)容例子(親測有效)
- Flutter之自定義Dialog實(shí)現(xiàn)版本更新彈窗功能的實(shí)現(xiàn)
- Flutter沉浸式狀態(tài)欄/AppBar導(dǎo)航欄/仿咸魚底部凸起導(dǎo)航欄效果
- flutter仿微信底部圖標(biāo)漸變功能的實(shí)現(xiàn)代碼
- Flutter實(shí)現(xiàn)仿微信底部菜單欄功能
- Flutter底部不規(guī)則導(dǎo)航的實(shí)現(xiàn)過程
- flutter BottomAppBar實(shí)現(xiàn)不規(guī)則底部導(dǎo)航欄
- Flutter實(shí)現(xiàn)底部導(dǎo)航欄
- Flutter實(shí)現(xiàn)底部菜單導(dǎo)航
- Flutter 底部彈窗ModelBottomSheet的使用示例
相關(guān)文章
Android DragImageView實(shí)現(xiàn)下拉拖動圖片放大效果
這篇文章主要為大家詳細(xì)介紹了Android DragImageView實(shí)現(xiàn)下拉拖動圖片放大效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-12-12Android輔助功能實(shí)現(xiàn)自動搶紅包(附源碼)
本篇文章主要介紹了Android輔助功能實(shí)現(xiàn)自動搶紅包(附源碼),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11解決android關(guān)于打開虛擬機(jī)時右側(cè)工具欄不顯示的問題
下面小編就為大家分享一篇解決android關(guān)于打開虛擬機(jī)時右側(cè)工具欄不顯示的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01通過案例分析Android WindowManager解析與騙取QQ密碼的過程
Windows Manager是一款窗口管理終端,可以遠(yuǎn)程連接到Linux的X桌面進(jìn)行管理,與服務(wù)器端產(chǎn)生一個session相互通信,通過本文給大家分享Android WindowManager解析與騙取QQ密碼的過程,需要的朋友參考下2016-01-01Android 斷點(diǎn)續(xù)傳的原理剖析與實(shí)例講解
這篇文章主要介紹了Android 斷點(diǎn)續(xù)傳的原理剖析與實(shí)例講解的相關(guān)資料,需要的朋友可以參考下2016-09-09Android協(xié)程的7個重要知識點(diǎn)匯總
在現(xiàn)代Android應(yīng)用開發(fā)中,協(xié)程(Coroutine)已經(jīng)成為一種不可或缺的技術(shù),它不僅簡化了異步編程,還提供了許多強(qiáng)大的工具和功能,可以在高階場景中發(fā)揮出色的表現(xiàn),本文將深入探討Coroutine重要知識點(diǎn),幫助開發(fā)者更好地利用Coroutine來構(gòu)建高效的Android應(yīng)用2023-09-09android 有阻尼下拉刷新列表的實(shí)現(xiàn)方法
下面小編就為大家分享一篇android 有阻尼下拉刷新列表的實(shí)現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助,一起跟隨小編過來看看吧2018-01-01