main.dart import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'conf/config.dart' as conf; import 'views/bottomBarItem.dart'; void main() { runApp(MaterialApp( title: conf.appName, theme: ThemeData( primarySwatch: Colors.red ), home: testPage(), ) ); } class testPage extends StatefulWidget { @override _testPageState createState() => _testPageState(); } class _testPageState extends State<testPage> { int current_index = 0; _changePage(index){ if (index != current_index){ setState(() { current_index = index; }); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("test bottom bar item"), ), body: pages[current_index], bottomNavigationBar: BottomNavigationBar( items: bottomNavItems, onTap: (index){ _changePage(index); }, currentIndex: current_index, type: BottomNavigationBarType.fixed, // other ), ); } }
other page (home.msg,userInfo) import 'package:flutter/material.dart'; class homePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Column( children: [ Text("home"), ], ), ), ); } }
pages import 'package:demo4/views/home.dart'; import 'package:flutter/material.dart'; import 'home.dart'; import 'msgPage.dart'; import 'userInfoPage.dart'; // 底部导航栏页面 final List<BottomNavigationBarItem> bottomNavItems = [ BottomNavigationBarItem( icon: Icon(Icons.home), title: Text("主页") ), BottomNavigationBarItem( icon: Icon(Icons.home), title: Text("消息") ), BottomNavigationBarItem( icon: Icon(Icons.home), title: Text("个人中心") ), ]; final List<Widget> pages = [homePage(),msgPage(),userInfoPage()];
原文地址:https://www.cnblogs.com/zengxm/p/13168497.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。