LifeMate — Personal, Family & Learning Companion

docs/owner-guide-and-delivery-plan
chore/phase1-repository-cleanup deploy/stable-web-apk deployment-static design/mobile-accessibility-v2 design/mobile-navigation-review docs/child-education-access-decision docs/offline-data-rescue-options docs/owner-guide-and-delivery-plan docs/phase1-policy-options docs/public-review-live-2026-10-15 feat/aparat-learning-library feat/child-device-safety feat/child-identity-schema feat/flutter-mobile-navigation feat/learning-content-operations feat/local-signing-preflight feat/online-family-stage0 feat/personal-encrypted-recovery feat/private-planner-series-api feat/public-review-page feat/standalone-weekly-planner feat/weekly-planner-android final-feature-1/iran-family-school fix/auth-abuse-expiry-safety fix/auth-expiry-after-lock fix/backend-request-safety fix/lifeguide-bootstrap-naming-ci fix/lifeguide-pages-qa-base-preflight fix/lifeguide-qa-pages-env-deployment fix/local-task-persistence fix/managed-child-session-boundary fix/personal-jalali-dates fix/personal-notification-controls fix/personal-upgrade-delivery-guard fix/sms-approval-gates fix/study-duration-display infra/cloudflare-neon-migration infra/lifeguide-cloudflare-qa infra/lifeguide-github-pages-qa infra/lifeguide-supabase-qa main phase-1/foundation-completion phase-2/product-foundation-identity phase-3/planner-school-family-core phase-4/ai-learning-wellbeing phase-5/hardening-observability-release test/android-reminder-acceptance test/personal-notification-settings test/personal-recovery-acceptance test/role-entry-apk
dart 128 lines 6 KB
Raw
1 import 'package:flutter/material.dart';
2
3 import 'reminder_coordinator.dart';
4 import 'reminders.dart';
5 import 'store.dart';
6
7 class StandaloneReminderSettings extends StatefulWidget {
8 const StandaloneReminderSettings(
9 {super.key, required this.store, required this.coordinator});
10 final StandaloneStore store;
11 final StandaloneReminderCoordinator coordinator;
12 @override
13 State<StandaloneReminderSettings> createState() =>
14 _StandaloneReminderSettingsState();
15 }
16
17 class _StandaloneReminderSettingsState extends State<StandaloneReminderSettings>
18 with WidgetsBindingObserver {
19 bool _busy = false;
20 @override
21 void initState() {
22 super.initState();
23 WidgetsBinding.instance.addObserver(this);
24 _run(() => widget.coordinator.refresh(widget.store));
25 }
26
27 @override
28 void dispose() {
29 WidgetsBinding.instance.removeObserver(this);
30 super.dispose();
31 }
32
33 @override
34 void didChangeAppLifecycleState(AppLifecycleState state) {
35 if (state == AppLifecycleState.resumed && !_busy) {
36 _run(() => widget.coordinator.refresh(widget.store));
37 }
38 }
39
40 Future<void> _run(Future<void> Function() work) async {
41 if (_busy) return;
42 setState(() => _busy = true);
43 try {
44 await work();
45 } catch (_) {/* Coordinator shows a safe Persian error. */} finally {
46 if (mounted) setState(() => _busy = false);
47 }
48 }
49
50 @override
51 Widget build(BuildContext context) => AnimatedBuilder(
52 animation: widget.coordinator,
53 builder: (context, _) {
54 final state = widget.coordinator.status;
55 return Scaffold(
56 appBar: AppBar(title: const Text('یادآوری‌های من')),
57 body: SafeArea(
58 child: ListView(padding: const EdgeInsets.all(20), children: [
59 const Text('یادآوری روی همین گوشی',
60 style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
61 const SizedBox(height: 12),
62 const Text(
63 'با اجازهٔ تو، نام همراهت و یک پیام عمومی نمایش داده می‌شود. عنوان خصوصی برنامه روی اعلان نمی‌آید. اینترنت و سرور لازم نیست.'),
64 const SizedBox(height: 16),
65 if (widget.coordinator.error != null)
66 Card(
67 child: Padding(
68 padding: const EdgeInsets.all(16),
69 child: Text(widget.coordinator.error!))),
70 if (_busy)
71 const LinearProgressIndicator(
72 semanticsLabel: 'در حال بررسی یادآوری'),
73 if (state != null && !state.supported)
74 const Text(
75 'یادآوری در این محیط در دسترس نیست؛ برنامه‌ها همچنان روی گوشی ذخیره می‌شوند.'),
76 if (state != null && state.supported) ...[
77 SwitchListTile.adaptive(
78 title: const Text('اعلان برنامه‌های من'),
79 subtitle: Text(
80 state.enabled ? 'انتخاب تو: روشن' : 'انتخاب تو: خاموش'),
81 value: state.enabled,
82 onChanged: _busy
83 ? null
84 : (value) => _run(() => value
85 ? widget.coordinator.enable(widget.store)
86 : widget.coordinator.disable(widget.store)),
87 ),
88 Text(state.permissionGranted
89 ? 'مجوز اعلان: داده شده'
90 : 'مجوز اعلان: داده نشده؛ برای اجازه دادن، اعلان را روشن کن.'),
91 const SizedBox(height: 12),
92 Text('یادآوری آیندهٔ زمان‌بندی‌شده: ${state.scheduledCount}'),
93 Text(state.timing == 'exact'
94 ? 'زمان‌بندی دقیق در دسترس است.'
95 : 'زمان‌بندی تقریبی است؛ ممکن است اندروید اعلان را با تأخیر نشان دهد.'),
96 if (state.exactAlarmSupported && !state.canScheduleExactAlarms)
97 OutlinedButton.icon(
98 onPressed: _busy
99 ? null
100 : () => _run(() => widget.coordinator
101 .requestExactAccess(widget.store)),
102 icon: const Icon(Icons.alarm),
103 label: const Text('بررسی اجازهٔ زمان‌بندی دقیق')),
104 ],
105 const SizedBox(height: 20),
106 const Text('پوشش یادآوری',
107 style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
108 const Text(
109 'تا ۲۸ روز آینده و حداکثر ۱۲۸ نوبت نزدیک‌تر آماده می‌شود. برنامه را مرتب باز کن تا روزهای بعد هم آماده شوند. برای هر برنامه، زمان یادآوری را جدا انتخاب کن.'),
110 if (state != null &&
111 state.eligibleCount > StandaloneReminderStatus.maximumReminders)
112 const Text(
113 'تعداد نوبت‌ها بیشتر از ظرفیت است؛ فعلاً فقط ۱۲۸ نوبت نزدیک‌تر آماده شده‌اند.'),
114 const SizedBox(height: 12),
115 const Text(
116 'خاموش‌کردن اجباری برنامه، تنظیم باتری، بی‌صدا بودن گوشی و مجوزهای اندروید می‌توانند اعلان یا صدای آن را متوقف کنند. اعلان زمان‌بندی‌شده تضمین شنیدن آلارم نیست.'),
117 const SizedBox(height: 16),
118 OutlinedButton.icon(
119 onPressed: _busy
120 ? null
121 : () =>
122 _run(() => widget.coordinator.refresh(widget.store)),
123 icon: const Icon(Icons.refresh),
124 label: const Text('بررسی دوباره')),
125 ])),
126 );
127 });
128 }