profile.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import 'package:chicken_farm/core/config/app_config.dart';
  2. import 'package:chicken_farm/stores/auth_store.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_riverpod/flutter_riverpod.dart';
  5. import 'package:chicken_farm/pages/home/_profile/user_info_card.dart';
  6. import 'package:chicken_farm/pages/home/_profile/upload_data_button.dart';
  7. import 'package:chicken_farm/pages/home/_profile/clear_cache_button.dart';
  8. import 'package:chicken_farm/pages/home/_profile/config_button.dart';
  9. import 'package:chicken_farm/pages/home/_profile/dict_config_button.dart';
  10. // import 'package:chicken_farm/pages/home/_profile/rfid_config_button.dart';
  11. // import 'package:chicken_farm/pages/home/_profile/scanner_light_button.dart';
  12. import 'package:chicken_farm/pages/home/_profile/logout_button.dart';
  13. final tapCountProvider = StateProvider<int>((ref) => 0);
  14. final lastTapTimeProvider = StateProvider<DateTime>((ref) => DateTime.now());
  15. class ProfilePage extends ConsumerWidget {
  16. const ProfilePage({super.key});
  17. @override
  18. Widget build(BuildContext context, WidgetRef ref) {
  19. final authState = ref.watch(authStoreProvider);
  20. final tapCount = ref.watch(tapCountProvider);
  21. // 判断是否应该显示字典维护按钮 (连续点击5次后显示)
  22. final showDictConfig = tapCount >= 5;
  23. void handleUserCardTap() {
  24. final now = DateTime.now();
  25. final previousTapTime = ref.read(lastTapTimeProvider);
  26. final tapCountNotifier = ref.read(tapCountProvider.notifier);
  27. final lastTapTimeNotifier = ref.read(lastTapTimeProvider.notifier);
  28. // 如果距离上次点击超过1秒,则重置计数
  29. if (now.difference(previousTapTime).inMilliseconds > 1000) {
  30. tapCountNotifier.state = 1;
  31. } else {
  32. tapCountNotifier.state = tapCount + 1;
  33. // 如果达到5次点击,显示提示
  34. if (tapCountNotifier.state == 5) {
  35. ScaffoldMessenger.of(context).showSnackBar(
  36. const SnackBar(
  37. content: Text('已解锁字典维护功能'),
  38. duration: Duration(seconds: 2),
  39. ),
  40. );
  41. }
  42. }
  43. lastTapTimeNotifier.state = now;
  44. }
  45. return Scaffold(
  46. body: Padding(
  47. padding: const EdgeInsets.all(16.0),
  48. child: Column(
  49. crossAxisAlignment: CrossAxisAlignment.start,
  50. children: [
  51. const SizedBox(height: 20),
  52. if (authState.state == AuthState.authenticated &&
  53. authState.user != null) ...[
  54. Expanded(
  55. child: SingleChildScrollView(
  56. child: Column(
  57. crossAxisAlignment: CrossAxisAlignment.start,
  58. children: [
  59. if (AppConfig.isOffline) ...[
  60. GestureDetector(
  61. onTap: handleUserCardTap,
  62. child: UserInfoCard(user: authState.user!),
  63. ),
  64. const SizedBox(height: 20),
  65. if (showDictConfig) ...[
  66. const DictConfigButton(),
  67. const SizedBox(height: 20),
  68. ],
  69. const ClearCacheButton(),
  70. const SizedBox(height: 20),
  71. ] else ...[
  72. UserInfoCard(user: authState.user!),
  73. const UploadDataButton(),
  74. const SizedBox(height: 20),
  75. const ClearCacheButton(),
  76. const SizedBox(height: 20),
  77. const ConfigButton(),
  78. const SizedBox(height: 20),
  79. // const RfidConfigButton(),
  80. // const SizedBox(height: 20),
  81. // const ScannerLightButton(),
  82. // const SizedBox(height: 20),
  83. const LogoutButton(),
  84. const SizedBox(height: 20),
  85. ],
  86. ],
  87. ),
  88. ),
  89. ),
  90. ] else ...[
  91. const Center(child: Text('加载中...')),
  92. ],
  93. ],
  94. ),
  95. ),
  96. );
  97. }
  98. }