import 'package:flutter/material.dart'; import 'package:qhdkfq_regulatory_flutter/home/home_page.dart'; import 'package:qhdkfq_regulatory_flutter/mine/mine_page.dart'; class MainPage extends StatefulWidget { const MainPage({super.key}); @override _MainPageState createState() => _MainPageState(); } class _MainPageState extends State { int _currentIndex = 0; // 页面列表 final List _pages = const [ HomePage(), MinePage() ]; // 页面标题 final List _titles = [ '首页', '我的', ]; @override Widget build(BuildContext context) { return Scaffold( appBar: _currentIndex == 1 ? null : AppBar( title: Text( _currentIndex == 0 ? "秦皇岛开发区泰盛安管" : _titles[_currentIndex], // _titles[_currentIndex], style: const TextStyle( fontSize: 17, color: Colors.white, ), ), centerTitle: true, // backgroundColor: Colors.blue, backgroundColor: _currentIndex == 0 ? Color(0xFF2A56F7) : Colors.blue, actions: [ // if (_currentIndex == 0) // IconButton(onPressed: () { // Navigator.push(context, MaterialPageRoute(builder: (context) => ScanPage() )); // }, icon: Image.asset("assets/images/scan.png", width: 20, height: 20,)) ], ), body: _pages[_currentIndex], bottomNavigationBar: BottomNavigationBar( currentIndex: _currentIndex, type: BottomNavigationBarType.fixed, // 保证超过3个图标不压缩 selectedItemColor: Colors.blue, unselectedItemColor: Colors.grey, onTap: (index) => setState(() => _currentIndex = index), items: [ BottomNavigationBarItem( icon: Image.asset('assets/tabbar/basics.png', width: 24, height: 24), activeIcon: Image.asset('assets/tabbar/basics_cur.png', width: 24, height: 24), label: '首页', ), BottomNavigationBarItem( icon: Image.asset('assets/tabbar/my.png', width: 24, height: 24), activeIcon: Image.asset('assets/tabbar/my_cur.png', width: 24, height: 24), label: '我的', ), ], ), ); } }