profile.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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: SizedBox(
  53. width: Platform.isAndroid ? MediaQuery.of(context).size.width : 300,
  54. height: MediaQuery.of(context).size.height,
  55. child: SingleChildScrollView(
  56. child: Column(
  57. crossAxisAlignment: CrossAxisAlignment.center,
  58. mainAxisAlignment: MainAxisAlignment.center,
  59. children: [
  60. if (authState.state == AuthState.authenticated) ...[
  61. if (AppConfig.isOffline) ...[
  62. GestureDetector(
  63. onTap: handleUserCardTap,
  64. child: UserInfoCard(user: authState.user!),
  65. ),
  66. const SizedBox(height: 20),
  67. if (showDictConfig) ...[
  68. const DictConfigButton(),
  69. const SizedBox(height: 20),
  70. ],
  71. if (AppConfig.isPda) ...[
  72. const PowerConfigButton(),
  73. const SizedBox(height: 20),
  74. ],
  75. const ClearCacheButton(),
  76. const SizedBox(height: 20),
  77. const ExportDataButton(),
  78. const SizedBox(height: 20),
  79. ] else ...[
  80. UserInfoCard(user: authState.user!),
  81. const SizedBox(height: 20),
  82. if (AppConfig.isPda) ...[
  83. const PowerConfigButton(),
  84. const SizedBox(height: 20),
  85. const UploadDataButton(),
  86. const SizedBox(height: 20),
  87. ],
  88. const ClearCacheButton(),
  89. const SizedBox(height: 20),
  90. const ConfigButton(),
  91. const SizedBox(height: 20),
  92. // const RfidConfigButton(),
  93. // const SizedBox(height: 20),
  94. // const ScannerLightButton(),
  95. // const SizedBox(height: 20),
  96. const LogoutButton(),
  97. const SizedBox(height: 20),
  98. ],
  99. Text(
  100. _buildVersionText(),
  101. textAlign: TextAlign.center,
  102. style: TextStyle(fontSize: 12, color: Colors.grey),
  103. ),
  104. ],
  105. ],
  106. ),
  107. ),
  108. ),
  109. ),
  110. );
  111. }
  112. String _buildVersionText() {
  113. final deviceType = AppConfig.isPda ? "PDA" : "APP";
  114. final mode = AppConfig.isOffline ? "_OFFLINE" : "";
  115. final deviceInfo = Platform.isAndroid ? "$deviceType$mode" : "WIN$mode";
  116. return 'ChickenFarm $deviceInfo Powered by IWB ©2025 \nVersion: ${AppConfig.appVersion}';
  117. }
  118. }