import 'package:flutter/material.dart'; import 'package:qhd_prevention/pages/home/scan_page.dart'; import 'package:qhd_prevention/pages/my_appbar.dart'; import 'home/home_page.dart'; import 'app/application_page.dart'; import 'mine/mine_page.dart'; import 'notif/notif_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(), ApplicationPage(), NotifPage(), MinePage(), ]; // 页面标题 final List _titles = ['首页', '应用中心', '通知公告', '我的']; @override Widget build(BuildContext context) { return Scaffold( appBar: _currentIndex == 1 ? null : MyAppbar( title: _currentIndex == 0 ? "泰盛安全首页" : _titles[_currentIndex], backgroundColor: Colors.blue, isBack: false, 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/application.png', width: 24, height: 24, ), activeIcon: Image.asset( 'assets/tabbar/application_cur.png', width: 24, height: 24, ), label: '应用', ), BottomNavigationBarItem( icon: Image.asset('assets/tabbar/works.png', width: 24, height: 24), activeIcon: Image.asset( 'assets/tabbar/works_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: '我的', ), ], ), ); } }