import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'home_page.dart'; import 'Information_page.dart'; import 'Mine_page.dart'; import 'Orders_page.dart'; class IndexPage extends StatefulWidget { _IndexPageState createState() => _IndexPageState(); } class _IndexPageState extends State { final List bottomTabs = [ BottomNavigationBarItem( icon: Icon(CupertinoIcons.home), title: Text('首页'), ), BottomNavigationBarItem( icon: Icon(CupertinoIcons.search), title: Text('资讯'), ), BottomNavigationBarItem( icon: Icon(CupertinoIcons.shopping_cart), title: Text('订单'), ), BottomNavigationBarItem( icon: Icon(CupertinoIcons.profile_circled), title: Text('我的'), ), ]; final List tabBodies = [ HomePage(), InformationPage(), OrdersPage(), MinePage(), ]; int currentIndex = 0; var currentPage; @override void initState() { super.initState(); currentPage = tabBodies[currentIndex]; } @override Widget build(BuildContext context) { // TODO: implement build return Scaffold( backgroundColor: Color.fromRGBO(244, 245, 245, 1), bottomNavigationBar: BottomNavigationBar( type: BottomNavigationBarType.fixed, currentIndex: currentIndex, items: bottomTabs, onTap: (index){ setState(() { currentIndex = index; currentPage = tabBodies[currentIndex]; }); }, ), body: currentPage, ); } }