智慧水务管理系统 - 精河县供水工程综合管理平台

home_page.dart 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'package:water_management_system/services/auth_service.dart';
  4. import 'package:water_management_system/pages/water/water_monitoring_page.dart';
  5. import 'package:water_management_system/pages/inspection/inspection_tasks_page.dart';
  6. import 'package:water_management_system/pages/revenue/revenue_page.dart';
  7. import 'package:water_management_system/utils/constants.dart';
  8. import 'package:water_management_system/widgets/custom_button.dart';
  9. class HomePage extends StatefulWidget {
  10. const HomePage({super.key});
  11. @override
  12. State<HomePage> createState() => _HomePageState();
  13. }
  14. class _HomePageState extends State<HomePage> {
  15. int _currentIndex = 0;
  16. final PageController _pageController = PageController();
  17. @override
  18. void dispose() {
  19. _pageController.dispose();
  20. super.dispose();
  21. }
  22. @override
  23. Widget build(BuildContext context) {
  24. return Scaffold(
  25. appBar: AppBar(
  26. title: const Text('智慧水务管理系统'),
  27. backgroundColor: AppConstants.primaryColor,
  28. elevation: 0,
  29. actions: [
  30. // 消息通知
  31. IconButton(
  32. icon: const Icon(Icons.notifications),
  33. onPressed: _showNotifications,
  34. tooltip: '消息通知',
  35. ),
  36. // 设置
  37. IconButton(
  38. icon: const Icon(Icons.settings),
  39. onPressed: _showSettings,
  40. tooltip: '设置',
  41. ),
  42. // 用户菜单
  43. PopupMenuButton<String>(
  44. onSelected: (value) {
  45. if (value == 'profile') {
  46. _showProfile();
  47. } else if (value == 'logout') {
  48. _showLogoutDialog();
  49. }
  50. },
  51. itemBuilder: (context) => [
  52. const PopupMenuItem(
  53. value: 'profile',
  54. child: Row(
  55. children: [
  56. Icon(Icons.person),
  57. SizedBox(width: 8),
  58. Text('个人资料'),
  59. ],
  60. ),
  61. ),
  62. const PopupMenuItem(
  63. value: 'logout',
  64. child: Row(
  65. children: [
  66. Icon(Icons.logout),
  67. SizedBox(width: 8),
  68. Text('退出登录'),
  69. ],
  70. ),
  71. ),
  72. ],
  73. ),
  74. ],
  75. ),
  76. body: PageView(
  77. controller: _pageController,
  78. physics: const NeverScrollableScrollPhysics(),
  79. children: [
  80. // 供水管理页面
  81. const WaterMonitoringPage(),
  82. // 巡检任务页面
  83. const InspectionTasksPage(),
  84. // 营收管理页面
  85. const RevenuePage(),
  86. ],
  87. ),
  88. bottomNavigationBar: BottomNavigationBar(
  89. currentIndex: _currentIndex,
  90. type: BottomNavigationBarType.fixed,
  91. onTap: (index) {
  92. setState(() {
  93. _currentIndex = index;
  94. _pageController.jumpToPage(index);
  95. });
  96. },
  97. items: const [
  98. BottomNavigationBarItem(
  99. icon: Icon(Icons.water_drop),
  100. label: '供水',
  101. ),
  102. BottomNavigationBarItem(
  103. icon: Icon(Icons.search),
  104. label: '巡检',
  105. ),
  106. BottomNavigationBarItem(
  107. icon: Icon(Icons.payment),
  108. label: '营收',
  109. ),
  110. ],
  111. selectedItemColor: AppConstants.primaryColor,
  112. unselectedItemColor: Colors.grey,
  113. ),
  114. );
  115. }
  116. void _showNotifications() {
  117. showModalBottomSheet(
  118. context: context,
  119. isScrollControlled: true,
  120. shape: const RoundedRectangleBorder(
  121. borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
  122. ),
  123. builder: (context) => const NotificationSheet(),
  124. );
  125. }
  126. void _showSettings() {
  127. Navigator.pushNamed(context, '/settings');
  128. }
  129. void _showProfile() {
  130. Navigator.pushNamed(context, '/profile');
  131. }
  132. void _showLogoutDialog() {
  133. showDialog(
  134. context: context,
  135. builder: (context) => AlertDialog(
  136. title: const Text('确认退出'),
  137. content: const Text('您确定要退出登录吗?'),
  138. actions: [
  139. TextButton(
  140. onPressed: () => Navigator.pop(context),
  141. child: const Text('取消'),
  142. ),
  143. TextButton(
  144. onPressed: () {
  145. Navigator.pop(context);
  146. Provider.of<AuthService>(context, listen: false).logout();
  147. Navigator.pushReplacementNamed(context, '/login');
  148. },
  149. style: TextButton.styleFrom(
  150. foregroundColor: AppConstants.errorColor,
  151. ),
  152. child: const Text('确定'),
  153. ),
  154. ],
  155. ),
  156. );
  157. }
  158. }
  159. class NotificationSheet extends StatelessWidget {
  160. const NotificationSheet({super.key});
  161. @override
  162. Widget build(BuildContext context) {
  163. return DraggableScrollableSheet(
  164. initialChildSize: 0.6,
  165. minChildSize: 0.4,
  166. maxChildSize: 0.9,
  167. expand: false,
  168. builder: (context, scrollController) => Container(
  169. decoration: const BoxDecoration(
  170. color: Colors.white,
  171. borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
  172. ),
  173. child: Column(
  174. children: [
  175. Container(
  176. width: 40,
  177. height: 4,
  178. margin: const EdgeInsets.only(top: 12, bottom: 20),
  179. decoration: BoxDecoration(
  180. color: Colors.grey[300],
  181. borderRadius: BorderRadius.circular(2),
  182. ),
  183. ),
  184. const Padding(
  185. padding: EdgeInsets.symmetric(horizontal: 16),
  186. child: Row(
  187. children: [
  188. Icon(Icons.notifications, size: 24),
  189. SizedBox(width: 12),
  190. Text(
  191. '消息通知',
  192. style: TextStyle(
  193. fontSize: 18,
  194. fontWeight: FontWeight.bold,
  195. ),
  196. ),
  197. ],
  198. ),
  199. ),
  200. const Divider(height: 24),
  201. Expanded(
  202. child: ListView.separated(
  203. controller: scrollController,
  204. padding: const EdgeInsets.symmetric(horizontal: 16),
  205. itemCount: 5,
  206. separatorBuilder: (context, index) => const Divider(height: 16),
  207. itemBuilder: (context, index) => NotificationItem(
  208. title: '供水异常告警',
  209. content: '区域A的水压低于正常阈值,请及时处理',
  210. time: '10分钟前',
  211. isRead: index < 2,
  212. ),
  213. ),
  214. ),
  215. ],
  216. ),
  217. ),
  218. );
  219. }
  220. }
  221. class NotificationItem extends StatelessWidget {
  222. final String title;
  223. final String content;
  224. final String time;
  225. final bool isRead;
  226. const NotificationItem({
  227. super.key,
  228. required this.title,
  229. required this.content,
  230. required this.time,
  231. required this.isRead,
  232. });
  233. @override
  234. Widget build(BuildContext context) {
  235. return Container(
  236. padding: const EdgeInsets.all(12),
  237. decoration: BoxDecoration(
  238. color: isRead ? Colors.white : Colors.blue[50],
  239. borderRadius: BorderRadius.circular(8),
  240. border: Border.all(
  241. color: isRead ? Colors.grey[200]! : Colors.blue[200]!,
  242. ),
  243. ),
  244. child: Column(
  245. crossAxisAlignment: CrossAxisAlignment.start,
  246. children: [
  247. Row(
  248. children: [
  249. Expanded(
  250. child: Text(
  251. title,
  252. style: TextStyle(
  253. fontSize: 16,
  254. fontWeight: FontWeight.bold,
  255. color: isRead ? Colors.black87 : Colors.blue[800],
  256. ),
  257. ),
  258. ),
  259. Text(
  260. time,
  261. style: TextStyle(
  262. fontSize: 12,
  263. color: Colors.grey[500],
  264. ),
  265. ),
  266. ],
  267. ),
  268. const SizedBox(height: 4),
  269. Text(
  270. content,
  271. style: TextStyle(
  272. fontSize: 14,
  273. color: isRead ? Colors.grey[600] : Colors.blue[700],
  274. ),
  275. ),
  276. ],
  277. ),
  278. );
  279. }
  280. }