Flutter實(shí)現(xiàn)底部導(dǎo)航-創(chuàng)新互聯(lián)

本文實(shí)例為大家分享了Flutter實(shí)現(xiàn)底部導(dǎo)航的具體代碼,供大家參考,具體內(nèi)容如下

岳池網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),岳池網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為岳池成百上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢(qián),請(qǐng)找那個(gè)售后服務(wù)好的岳池做網(wǎng)站的公司定做!

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;
      });
     },
    ),
   ),
  );
 }
}

當(dāng)前文章:Flutter實(shí)現(xiàn)底部導(dǎo)航-創(chuàng)新互聯(lián)
當(dāng)前路徑:http://www.muchs.cn/article42/dssohc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、網(wǎng)頁(yè)設(shè)計(jì)公司網(wǎng)站收錄、云服務(wù)器Google、企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司