| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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';
- import 'package:chicken_farm/pages/home/_profile/export_data_button.dart';
- final tapCountProvider = StateProvider<int>((ref) => 0);
- final lastTapTimeProvider = StateProvider<DateTime>((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),
- const ExportDataButton(),
- 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('加载中...')),
- ],
- ],
- ),
- ),
- );
- }
- }
|