真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Flutter實現(xiàn)底部導航

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

定州ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信: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 State with TickerProviderStateMixin{

 int _tabIndex = 0;

 List _navigationViews;

 var appBarTitles = ['首頁', '發(fā)現(xiàn)', '我的'];

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

底部包含三個導航按鈕,分別對應(yīng)三個界面:

firstPage.dart

import 'package:flutter/material.dart';

class FirstPage extends StatefulWidget {
 @override
 State createState() => 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
 State createState() => 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
 State createState() => ThirdPageState();

}

class ThirdPageState extends State{
 @override
 Widget build(BuildContext context) {
  return new Scaffold(
   body: new Center(
    child: new Text('我是界面三'),
   ),
  );
 }
}

運行截圖:

Flutter實現(xiàn)底部導航

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。


網(wǎng)頁標題:Flutter實現(xiàn)底部導航
URL標題:http://weahome.cn/article/pcdpdi.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部