flutter_integrated_whb/lib/pages/main_tab.dart

115 lines
3.3 KiB
Dart
Raw Permalink Normal View History

2025-07-11 11:03:21 +08:00
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<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
: 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: '我的',
),
],
),
);
}
}