Flutter实现底部导航-创新互联

本文实例为大家分享了Flutter实现底部导航的具体代码,供大家参考,具体内容如下

岳池网站建设公司创新互联,岳池网站设计制作,有大型网站制作公司丰富经验。已为岳池成百上千提供企业网站建设服务。企业网站搭建\成都外贸网站建设公司要多少钱,请找那个售后服务好的岳池做网站的公司定做!

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<MyApp> with TickerProviderStateMixin{

 int _tabIndex = 0;

 List<BottomNavigationBarItem> _navigationViews;

 var appBarTitles = ['首页', '发现', '我的'];

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

当前文章:Flutter实现底部导航-创新互联
当前路径:https://www.cdcxhl.com/article42/dssohc.html

成都网站建设公司_创新互联,为您提供虚拟主机网页设计公司网站收录云服务器Google企业网站制作

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

网站建设网站维护公司