import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:zhiying_base_widget/pages/main_page.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; class HomePage extends StatefulWidget { HomePage({Key key}) : super(key: key); @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { int _currentIndex = 0; List _tab = List(); List _contentWidgets = List(); @override void initState() { _tab.add('首页'); _tab.add('个人中心'); _contentWidgets = _tab.map((item) { return PageFactory.create('mainPage', Map()); }).toList(); super.initState(); } @override Widget build(BuildContext context) { print('home_page build'); return Scaffold( body: IndexedStack( index: _currentIndex, children: _contentWidgets, ), //底部导航栏 bottomNavigationBar: createBottomNavigationBar()); } Widget createBottomNavigationBar() { List items = List(); for (int i = 0; i < _tab.length; i++) { items.add(BottomNavigationBarItem( icon: Container( width: 24, height: 24, margin: EdgeInsets.only(bottom: 4), child: CachedNetworkImage( imageUrl: "http://www.hairuyi.com/Upload/slide/1594279903_1_0.png", fit: BoxFit.fitWidth, ), ), title: Text('tab2'))); } if (items.length < 2) { return Container(); } return BottomNavigationBar( backgroundColor: Colors.white, type: BottomNavigationBarType.fixed, selectedFontSize: 11, unselectedFontSize: 11, currentIndex: _currentIndex, elevation: 0, onTap: ((index) { setState(() { _currentIndex = index; }); }), //底部导航栏 items: items); } }