qhd-prevention-flutter/lib/pages/main_tab.dart

90 lines
2.7 KiB
Dart
Raw Normal View History

2025-07-03 09:45:15 +08:00
import 'package:flutter/material.dart';
import 'package:qhd_prevention/pages/home/scan_page.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<MainPage> {
int _currentIndex = 0;
// 页面列表
final List<Widget> _pages = const [
HomePage(),
ApplicationPage(),
NotifPage(),
MinePage()
];
// 页面标题
final List<String> _titles = [
'首页',
'应用中心',
'通知公告',
'我的',
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _currentIndex == 1
? null
: AppBar(
title: Text(
_currentIndex == 0 ? "泰盛安全首页" : _titles[_currentIndex],
style: const TextStyle(
fontSize: 17,
color: Colors.white,
),
),
centerTitle: true,
backgroundColor: 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/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: '我的',
),
],
),
);
}
}