profile.dart 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import 'dart:io';
  2. import 'package:chicken_farm/core/config/app_config.dart';
  3. import 'package:chicken_farm/stores/auth_store.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_riverpod/flutter_riverpod.dart';
  6. import 'package:chicken_farm/pages/home/_profile/user_info_card.dart';
  7. import 'package:chicken_farm/pages/home/_profile/upload_data_button.dart';
  8. import 'package:chicken_farm/pages/home/_profile/clear_cache_button.dart';
  9. import 'package:chicken_farm/pages/home/_profile/config_button.dart';
  10. import 'package:chicken_farm/pages/home/_profile/dict_config_button.dart';
  11. import 'package:chicken_farm/pages/home/_profile/power_config_button.dart';
  12. // import 'package:chicken_farm/pages/home/_profile/rfid_config_button.dart';
  13. // import 'package:chicken_farm/pages/home/_profile/scanner_light_button.dart';
  14. import 'package:chicken_farm/pages/home/_profile/logout_button.dart';
  15. import 'package:chicken_farm/pages/home/_profile/export_data_button.dart';
  16. final tapCountProvider = StateProvider<int>((ref) => 0);
  17. final lastTapTimeProvider = StateProvider<DateTime>((ref) => DateTime.now());
  18. class ProfilePage extends ConsumerWidget {
  19. const ProfilePage({super.key});
  20. @override
  21. Widget build(BuildContext context, WidgetRef ref) {
  22. final authState = ref.watch(authStoreProvider);
  23. final tapCount = ref.watch(tapCountProvider);
  24. // 判断是否应该显示字典维护按钮 (连续点击5次后显示)
  25. final showDictConfig = tapCount >= 5;
  26. void handleUserCardTap() {
  27. final now = DateTime.now();
  28. final previousTapTime = ref.read(lastTapTimeProvider);
  29. final tapCountNotifier = ref.read(tapCountProvider.notifier);
  30. final lastTapTimeNotifier = ref.read(lastTapTimeProvider.notifier);
  31. // 如果距离上次点击超过1秒,则重置计数
  32. if (now.difference(previousTapTime).inMilliseconds > 1000) {
  33. tapCountNotifier.state = 1;
  34. } else {
  35. tapCountNotifier.state = tapCount + 1;
  36. // 如果达到5次点击,显示提示
  37. if (tapCountNotifier.state == 5) {
  38. ScaffoldMessenger.of(context).showSnackBar(
  39. const SnackBar(
  40. content: Text('已解锁字典维护功能'),
  41. duration: Duration(seconds: 2),
  42. ),
  43. );
  44. }
  45. }
  46. lastTapTimeNotifier.state = now;
  47. }
  48. return Scaffold(
  49. key: super.key,
  50. body: Padding(
  51. padding: const EdgeInsets.all(20),
  52. child: Center( // 添加居中组件
  53. child: SingleChildScrollView(
  54. child: SizedBox(
  55. width: Platform.isAndroid
  56. ? MediaQuery.of(context).size.width * 0.8 // 使用屏幕宽度的80%
  57. : MediaQuery.of(context).size.width > 350
  58. ? 350 // 限制最大宽度
  59. : MediaQuery.of(context).size.width,
  60. child: Column(
  61. crossAxisAlignment: CrossAxisAlignment.center,
  62. mainAxisAlignment: MainAxisAlignment.center,
  63. children: [
  64. if (authState.state == AuthState.authenticated) ...[
  65. if (AppConfig.isOffline) ...[
  66. GestureDetector(
  67. onTap: handleUserCardTap,
  68. child: UserInfoCard(user: authState.user!),
  69. ),
  70. const SizedBox(height: 20),
  71. if (showDictConfig) ...[
  72. const DictConfigButton(),
  73. const SizedBox(height: 20),
  74. ],
  75. if (AppConfig.isPda) ...[
  76. const PowerConfigButton(),
  77. const SizedBox(height: 20),
  78. ],
  79. const ClearCacheButton(),
  80. const SizedBox(height: 20),
  81. const ExportDataButton(),
  82. const SizedBox(height: 20),
  83. ] else ...[
  84. UserInfoCard(user: authState.user!),
  85. const SizedBox(height: 20),
  86. if (AppConfig.isPda) ...[
  87. const PowerConfigButton(),
  88. const SizedBox(height: 20),
  89. const UploadDataButton(),
  90. const SizedBox(height: 20),
  91. ],
  92. const ClearCacheButton(),
  93. const SizedBox(height: 20),
  94. const ConfigButton(),
  95. const SizedBox(height: 20),
  96. // const RfidConfigButton(),
  97. // const SizedBox(height: 20),
  98. // const ScannerLightButton(),
  99. // const SizedBox(height: 20),
  100. const LogoutButton(),
  101. const SizedBox(height: 20),
  102. ],
  103. Text(
  104. _buildVersionText(),
  105. textAlign: TextAlign.center,
  106. style: TextStyle(fontSize: 12, color: Colors.grey),
  107. ),
  108. ],
  109. ],
  110. ),
  111. ),
  112. ),
  113. ),
  114. ),
  115. );
  116. }
  117. String _buildVersionText() {
  118. final deviceType = AppConfig.isPda ? "PDA" : "APP";
  119. final mode = AppConfig.isOffline ? "_OFFLINE" : "";
  120. final deviceInfo = Platform.isAndroid ? "$deviceType$mode" : "WIN$mode";
  121. return 'ChickenFarm $deviceInfo Powered by IWB ©2025 \nVersion: ${AppConfig.appVersion}';
  122. }
  123. }