| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- import 'package:flutter/material.dart';
- import 'package:provider/provider.dart';
- import 'package:water_management_system/services/auth_service.dart';
- import 'package:water_management_system/pages/water/water_monitoring_page.dart';
- import 'package:water_management_system/pages/inspection/inspection_tasks_page.dart';
- import 'package:water_management_system/pages/revenue/revenue_page.dart';
- import 'package:water_management_system/utils/constants.dart';
- import 'package:water_management_system/widgets/custom_button.dart';
-
- class HomePage extends StatefulWidget {
- const HomePage({super.key});
-
- @override
- State<HomePage> createState() => _HomePageState();
- }
-
- class _HomePageState extends State<HomePage> {
- int _currentIndex = 0;
- final PageController _pageController = PageController();
-
- @override
- void dispose() {
- _pageController.dispose();
- super.dispose();
- }
-
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: const Text('智慧水务管理系统'),
- backgroundColor: AppConstants.primaryColor,
- elevation: 0,
- actions: [
- // 消息通知
- IconButton(
- icon: const Icon(Icons.notifications),
- onPressed: _showNotifications,
- tooltip: '消息通知',
- ),
- // 设置
- IconButton(
- icon: const Icon(Icons.settings),
- onPressed: _showSettings,
- tooltip: '设置',
- ),
- // 用户菜单
- PopupMenuButton<String>(
- onSelected: (value) {
- if (value == 'profile') {
- _showProfile();
- } else if (value == 'logout') {
- _showLogoutDialog();
- }
- },
- itemBuilder: (context) => [
- const PopupMenuItem(
- value: 'profile',
- child: Row(
- children: [
- Icon(Icons.person),
- SizedBox(width: 8),
- Text('个人资料'),
- ],
- ),
- ),
- const PopupMenuItem(
- value: 'logout',
- child: Row(
- children: [
- Icon(Icons.logout),
- SizedBox(width: 8),
- Text('退出登录'),
- ],
- ),
- ),
- ],
- ),
- ],
- ),
- body: PageView(
- controller: _pageController,
- physics: const NeverScrollableScrollPhysics(),
- children: [
- // 供水管理页面
- const WaterMonitoringPage(),
- // 巡检任务页面
- const InspectionTasksPage(),
- // 营收管理页面
- const RevenuePage(),
- ],
- ),
- bottomNavigationBar: BottomNavigationBar(
- currentIndex: _currentIndex,
- type: BottomNavigationBarType.fixed,
- onTap: (index) {
- setState(() {
- _currentIndex = index;
- _pageController.jumpToPage(index);
- });
- },
- items: const [
- BottomNavigationBarItem(
- icon: Icon(Icons.water_drop),
- label: '供水',
- ),
- BottomNavigationBarItem(
- icon: Icon(Icons.search),
- label: '巡检',
- ),
- BottomNavigationBarItem(
- icon: Icon(Icons.payment),
- label: '营收',
- ),
- ],
- selectedItemColor: AppConstants.primaryColor,
- unselectedItemColor: Colors.grey,
- ),
- );
- }
-
- void _showNotifications() {
- showModalBottomSheet(
- context: context,
- isScrollControlled: true,
- shape: const RoundedRectangleBorder(
- borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
- ),
- builder: (context) => const NotificationSheet(),
- );
- }
-
- void _showSettings() {
- Navigator.pushNamed(context, '/settings');
- }
-
- void _showProfile() {
- Navigator.pushNamed(context, '/profile');
- }
-
- void _showLogoutDialog() {
- showDialog(
- context: context,
- builder: (context) => AlertDialog(
- title: const Text('确认退出'),
- content: const Text('您确定要退出登录吗?'),
- actions: [
- TextButton(
- onPressed: () => Navigator.pop(context),
- child: const Text('取消'),
- ),
- TextButton(
- onPressed: () {
- Navigator.pop(context);
- Provider.of<AuthService>(context, listen: false).logout();
- Navigator.pushReplacementNamed(context, '/login');
- },
- style: TextButton.styleFrom(
- foregroundColor: AppConstants.errorColor,
- ),
- child: const Text('确定'),
- ),
- ],
- ),
- );
- }
- }
-
- class NotificationSheet extends StatelessWidget {
- const NotificationSheet({super.key});
-
- @override
- Widget build(BuildContext context) {
- return DraggableScrollableSheet(
- initialChildSize: 0.6,
- minChildSize: 0.4,
- maxChildSize: 0.9,
- expand: false,
- builder: (context, scrollController) => Container(
- decoration: const BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
- ),
- child: Column(
- children: [
- Container(
- width: 40,
- height: 4,
- margin: const EdgeInsets.only(top: 12, bottom: 20),
- decoration: BoxDecoration(
- color: Colors.grey[300],
- borderRadius: BorderRadius.circular(2),
- ),
- ),
- const Padding(
- padding: EdgeInsets.symmetric(horizontal: 16),
- child: Row(
- children: [
- Icon(Icons.notifications, size: 24),
- SizedBox(width: 12),
- Text(
- '消息通知',
- style: TextStyle(
- fontSize: 18,
- fontWeight: FontWeight.bold,
- ),
- ),
- ],
- ),
- ),
- const Divider(height: 24),
- Expanded(
- child: ListView.separated(
- controller: scrollController,
- padding: const EdgeInsets.symmetric(horizontal: 16),
- itemCount: 5,
- separatorBuilder: (context, index) => const Divider(height: 16),
- itemBuilder: (context, index) => NotificationItem(
- title: '供水异常告警',
- content: '区域A的水压低于正常阈值,请及时处理',
- time: '10分钟前',
- isRead: index < 2,
- ),
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
-
- class NotificationItem extends StatelessWidget {
- final String title;
- final String content;
- final String time;
- final bool isRead;
-
- const NotificationItem({
- super.key,
- required this.title,
- required this.content,
- required this.time,
- required this.isRead,
- });
-
- @override
- Widget build(BuildContext context) {
- return Container(
- padding: const EdgeInsets.all(12),
- decoration: BoxDecoration(
- color: isRead ? Colors.white : Colors.blue[50],
- borderRadius: BorderRadius.circular(8),
- border: Border.all(
- color: isRead ? Colors.grey[200]! : Colors.blue[200]!,
- ),
- ),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- Expanded(
- child: Text(
- title,
- style: TextStyle(
- fontSize: 16,
- fontWeight: FontWeight.bold,
- color: isRead ? Colors.black87 : Colors.blue[800],
- ),
- ),
- ),
- Text(
- time,
- style: TextStyle(
- fontSize: 12,
- color: Colors.grey[500],
- ),
- ),
- ],
- ),
- const SizedBox(height: 4),
- Text(
- content,
- style: TextStyle(
- fontSize: 14,
- color: isRead ? Colors.grey[600] : Colors.blue[700],
- ),
- ),
- ],
- ),
- );
- }
- }
|