profile.dart 4.3 KB

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