import 'package:chicken_farm/core/config/app_config.dart'; import 'package:chicken_farm/stores/auth_store.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:chicken_farm/pages/home/_profile/user_info_card.dart'; import 'package:chicken_farm/pages/home/_profile/upload_data_button.dart'; import 'package:chicken_farm/pages/home/_profile/clear_cache_button.dart'; import 'package:chicken_farm/pages/home/_profile/config_button.dart'; import 'package:chicken_farm/pages/home/_profile/dict_config_button.dart'; // import 'package:chicken_farm/pages/home/_profile/rfid_config_button.dart'; // import 'package:chicken_farm/pages/home/_profile/scanner_light_button.dart'; import 'package:chicken_farm/pages/home/_profile/logout_button.dart'; final tapCountProvider = StateProvider((ref) => 0); final lastTapTimeProvider = StateProvider((ref) => DateTime.now()); class ProfilePage extends ConsumerWidget { const ProfilePage({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final authState = ref.watch(authStoreProvider); final tapCount = ref.watch(tapCountProvider); // 判断是否应该显示字典维护按钮 (连续点击5次后显示) final showDictConfig = tapCount >= 5; void handleUserCardTap() { final now = DateTime.now(); final previousTapTime = ref.read(lastTapTimeProvider); final tapCountNotifier = ref.read(tapCountProvider.notifier); final lastTapTimeNotifier = ref.read(lastTapTimeProvider.notifier); // 如果距离上次点击超过1秒,则重置计数 if (now.difference(previousTapTime).inMilliseconds > 1000) { tapCountNotifier.state = 1; } else { tapCountNotifier.state = tapCount + 1; // 如果达到5次点击,显示提示 if (tapCountNotifier.state == 5) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('已解锁字典维护功能'), duration: Duration(seconds: 2), ), ); } } lastTapTimeNotifier.state = now; } return Scaffold( body: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const SizedBox(height: 20), if (authState.state == AuthState.authenticated && authState.user != null) ...[ Expanded( child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ if (AppConfig.isOffline) ...[ GestureDetector( onTap: handleUserCardTap, child: UserInfoCard(user: authState.user!), ), const SizedBox(height: 20), if (showDictConfig) ...[ const DictConfigButton(), const SizedBox(height: 20), ], const ClearCacheButton(), const SizedBox(height: 20), ] else ...[ UserInfoCard(user: authState.user!), const UploadDataButton(), const SizedBox(height: 20), const ClearCacheButton(), const SizedBox(height: 20), const ConfigButton(), const SizedBox(height: 20), // const RfidConfigButton(), // const SizedBox(height: 20), // const ScannerLightButton(), // const SizedBox(height: 20), const LogoutButton(), const SizedBox(height: 20), ], ], ), ), ), ] else ...[ const Center(child: Text('加载中...')), ], ], ), ), ); } }