profile.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 (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. const ExportDataButton(),
  72. const SizedBox(height: 20),
  73. ] else ...[
  74. UserInfoCard(user: authState.user!),
  75. const SizedBox(height: 20),
  76. if (AppConfig.isPda) ...[
  77. const UploadDataButton(),
  78. const SizedBox(height: 20),
  79. ],
  80. const ClearCacheButton(),
  81. const SizedBox(height: 20),
  82. const ConfigButton(),
  83. const SizedBox(height: 20),
  84. // const RfidConfigButton(),
  85. // const SizedBox(height: 20),
  86. // const ScannerLightButton(),
  87. // const SizedBox(height: 20),
  88. const LogoutButton(),
  89. const SizedBox(height: 20),
  90. ],
  91. ],
  92. ),
  93. ),
  94. ),
  95. ),
  96. );
  97. }
  98. }