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)入三個(gè)界面
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 = ['首頁(yè)', '發(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;
});
},
),
),
);
}
}
底部包含三個(gè)導(dǎo)航按鈕,分別對(duì)應(yīng)三個(gè)界面:
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('這是第一個(gè)界面'),
),
);
}
}
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("這是我第二個(gè)頁(yè)面"),
),
);
}
}
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)行截圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- flutter實(shí)現(xiàn)更新彈窗內(nèi)容例子(親測(cè)有效)
- Flutter之自定義Dialog實(shí)現(xiàn)版本更新彈窗功能的實(shí)現(xiàn)
- Flutter沉浸式狀態(tài)欄/AppBar導(dǎo)航欄/仿咸魚(yú)底部凸起導(dǎo)航欄效果
- flutter仿微信底部圖標(biāo)漸變功能的實(shí)現(xiàn)代碼
- Flutter實(shí)現(xiàn)仿微信底部菜單欄功能
- Flutter底部不規(guī)則導(dǎo)航的實(shí)現(xiàn)過(guò)程
- 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簡(jiǎn)單實(shí)現(xiàn)屏幕下方Tab菜單的方法
這篇文章主要介紹了Android簡(jiǎn)單實(shí)現(xiàn)屏幕下方Tab菜單的方法,簡(jiǎn)單分析了Android實(shí)現(xiàn)tab菜單所涉及的界面布局及功能相關(guān)操作技巧,需要的朋友可以參考下2016-08-08
Android 監(jiān)聽(tīng)手機(jī)GPS打開(kāi)狀態(tài)實(shí)現(xiàn)代碼
這篇文章主要介紹了Android 監(jiān)聽(tīng)手機(jī)GPS打開(kāi)狀態(tài)實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2017-05-05
Android邊播放邊緩存視頻框架AndroidVideoCache詳解
這篇文章主要為大家介紹了Android邊播放邊緩存視頻框架AndroidVideoCache詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09
Flutter網(wǎng)絡(luò)請(qǐng)求庫(kù)DIO的基本使用
這篇文章主要介紹了Flutter網(wǎng)絡(luò)請(qǐng)求庫(kù)DIO的基本使用,幫助大家更好的理解和學(xué)習(xí)使用Flutter,感興趣的朋友可以了解下2021-04-04
Kotlin ViewModelProvider.Factory的使用實(shí)例詳解
這篇文章主要介紹了Kotlin ViewModelProvider.Factory的使用,在我們使用 ViewModel 的時(shí)候,我們會(huì)發(fā)現(xiàn),有的時(shí)候我們需要用到 ViewModelFactory,有的時(shí)候不需要2023-02-02
Android 超詳細(xì)深刨Activity Result API的使用
這篇文章主要介紹了Android開(kāi)發(fā)中Activity Result API的使用,掌握了它以后你就可以放棄startActivityForResult了,感興趣的朋友一起來(lái)看看吧2022-03-03
Android基于ViewFilpper實(shí)現(xiàn)文字LED顯示效果示例
這篇文章主要介紹了Android基于ViewFilpper實(shí)現(xiàn)文字LED顯示效果,結(jié)合完整實(shí)例形式分析了Android使用ViewFilpper實(shí)現(xiàn)文字LED顯示動(dòng)畫(huà)效果的相關(guān)步驟與實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-08-08
Android開(kāi)發(fā)中PopupWindow用法實(shí)例分析
這篇文章主要介紹了Android開(kāi)發(fā)中PopupWindow用法,結(jié)合實(shí)例形式分析了PopupWindow彈出窗口效果的使用技巧,需要的朋友可以參考下2016-02-02

