profile.dart 4.2 KB

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