国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Flutter實(shí)現(xiàn)底部導(dǎo)航

2019-10-21 21:25:29
字體:
供稿:網(wǎng)友

本文實(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 = ['首頁', '發(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è)頁面"),   ),  ); }}

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)行截圖:

Flutter,底部導(dǎo)航

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到Android開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 淮南市| 肇东市| 阿拉善盟| 乌拉特中旗| 南乐县| 广丰县| 新昌县| 罗甸县| 衡山县| 扶沟县| 南陵县| 得荣县| 平山县| 综艺| 黑河市| 吉木乃县| 信宜市| 沈丘县| 交口县| 建德市| 德清县| 正宁县| 宁德市| 玛纳斯县| 怀安县| 临江市| 左权县| 彝良县| 屏山县| 开江县| 临洮县| 德阳市| 蒲江县| 保德县| 广河县| 樟树市| 米泉市| 垣曲县| 桃江县| 富顺县| 罗江县|