LifeMate — Personal, Family & Learning Companion
feat/local-signing-preflight
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
| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter/foundation.dart'; |
| 3 | import 'mobile_home.dart'; |
| 4 | import 'plan_sync.dart'; |
| 5 | |
| 6 | /// Displays one selected record. Mutations stay with the caller's PlanSync path. |
| 7 | class PlanDetailsPage extends StatefulWidget { |
| 8 | const PlanDetailsPage( |
| 9 | {super.key, |
| 10 | required this.item, |
| 11 | this.sharedUpdates, |
| 12 | required this.canEdit, |
| 13 | required this.canStudy, |
| 14 | required this.offline, |
| 15 | required this.onAction, |
| 16 | required this.kindLabel, |
| 17 | required this.dateLabel, |
| 18 | required this.errorLabel}); |
| 19 | final Map<String, dynamic> item; |
| 20 | final ValueListenable<Map<String, dynamic>?>? sharedUpdates; |
| 21 | final bool canEdit, canStudy, offline; |
| 22 | final Future<MutationOutcome?> Function(Map<String, dynamic>, String) |
| 23 | onAction; |
| 24 | final String Function(String) kindLabel; |
| 25 | final String Function(dynamic) dateLabel; |
| 26 | final String Function(Object) errorLabel; |
| 27 | @override |
| 28 | State<PlanDetailsPage> createState() => _PlanDetailsPageState(); |
| 29 | } |
| 30 | |
| 31 | class _PlanDetailsPageState extends State<PlanDetailsPage> |
| 32 | with WidgetsBindingObserver { |
| 33 | late Map<String, dynamic> item = Map.of(widget.item); |
| 34 | bool busy = false, acknowledged = false; |
| 35 | String? error, pendingAction; |
| 36 | bool snapshotInvalid = false, active = true; |
| 37 | @override |
| 38 | void initState() { |
| 39 | super.initState(); |
| 40 | WidgetsBinding.instance.addObserver(this); |
| 41 | widget.sharedUpdates?.addListener(sharedChanged); |
| 42 | } |
| 43 | |
| 44 | void sharedChanged() { |
| 45 | if (!mounted || !active) return; |
| 46 | final latest = widget.sharedUpdates?.value; |
| 47 | setState(() { |
| 48 | snapshotInvalid = latest == null; |
| 49 | item = latest == null ? {} : Map.of(latest); |
| 50 | }); |
| 51 | } |
| 52 | |
| 53 | @override |
| 54 | void didChangeAppLifecycleState(AppLifecycleState state) { |
| 55 | active = state == AppLifecycleState.resumed; |
| 56 | if (!widget.canEdit && !active && mounted) { |
| 57 | setState(() { |
| 58 | snapshotInvalid = true; |
| 59 | item = {}; |
| 60 | }); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | @override |
| 65 | void dispose() { |
| 66 | widget.sharedUpdates?.removeListener(sharedChanged); |
| 67 | WidgetsBinding.instance.removeObserver(this); |
| 68 | super.dispose(); |
| 69 | } |
| 70 | |
| 71 | Future<void> act(String action) async { |
| 72 | if (busy) return; |
| 73 | setState(() { |
| 74 | busy = true; |
| 75 | pendingAction = action; |
| 76 | error = null; |
| 77 | }); |
| 78 | try { |
| 79 | final outcome = await widget.onAction(item, action); |
| 80 | if (!mounted || outcome == null) return; |
| 81 | if (action == 'archive') { |
| 82 | Navigator.pop(context); |
| 83 | return; |
| 84 | } |
| 85 | setState(() { |
| 86 | item = Map.of(outcome.item ?? item); |
| 87 | item['pending_sync'] = outcome.queued; |
| 88 | acknowledged = !outcome.queued; |
| 89 | }); |
| 90 | } catch (failure) { |
| 91 | if (mounted) { |
| 92 | setState(() { |
| 93 | error = widget.errorLabel(failure); |
| 94 | if (action == 'study') { |
| 95 | snapshotInvalid = true; |
| 96 | item = {}; |
| 97 | } |
| 98 | }); |
| 99 | } |
| 100 | } finally { |
| 101 | if (mounted) setState(() => busy = false); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | @override |
| 106 | Widget build(BuildContext context) { |
| 107 | if (snapshotInvalid) { |
| 108 | return Scaffold( |
| 109 | appBar: AppBar(title: const Text('وضعیت کار')), |
| 110 | body: Center( |
| 111 | child: Padding( |
| 112 | padding: const EdgeInsets.all(24), |
| 113 | child: Column(mainAxisSize: MainAxisSize.min, children: [ |
| 114 | const Text( |
| 115 | 'اطلاعات تازه در دسترس نیست. برای بررسی وضعیت و دسترسی، به فهرست برنامه برگرد.'), |
| 116 | if (error != null) Text(error!), |
| 117 | TextButton( |
| 118 | onPressed: () => Navigator.pop(context), |
| 119 | child: const Text('بازگشت به برنامه')), |
| 120 | ])))); |
| 121 | } |
| 122 | final pending = item['pending_sync'] == true; |
| 123 | final status = item['status']?.toString() ?? 'planned'; |
| 124 | final stateLabel = switch (status) { |
| 125 | 'completed' => 'انجامشده', |
| 126 | 'in_progress' => 'در حال انجام', |
| 127 | 'cancelled' => 'بایگانیشده', |
| 128 | _ => 'برنامهریزیشده', |
| 129 | }; |
| 130 | final visibility = switch (item['visibility']) { |
| 131 | 'parent_guardian' => 'سرپرستان مجاز', |
| 132 | 'selected_members' => 'اعضای انتخابشده', |
| 133 | 'family' => 'اعضای مجاز خانواده', |
| 134 | _ => 'فقط من', |
| 135 | }; |
| 136 | final seconds = num.tryParse((item['planned_duration_seconds'] ?? |
| 137 | item['plannedDurationSeconds'] ?? |
| 138 | 0) |
| 139 | .toString()) ?? |
| 140 | 0; |
| 141 | final minutes = seconds > 0 |
| 142 | ? (seconds / 60).round() |
| 143 | : (num.tryParse(item['duration_minutes'].toString()) ?? 0); |
| 144 | return PopScope( |
| 145 | canPop: !busy, |
| 146 | child: Scaffold( |
| 147 | key: const ValueKey('plan-details'), |
| 148 | backgroundColor: MobileHomeMenu.paper, |
| 149 | appBar: AppBar(title: const Text('جزئیات تکلیف')), |
| 150 | body: SafeArea( |
| 151 | child: ListView(padding: const EdgeInsets.all(20), children: [ |
| 152 | Text( |
| 153 | '${widget.kindLabel(item['kind']?.toString() ?? 'task')} · $stateLabel', |
| 154 | style: const TextStyle(color: MobileHomeMenu.accent)), |
| 155 | const SizedBox(height: 12), |
| 156 | Text(item['title']?.toString() ?? '', |
| 157 | style: Theme.of(context) |
| 158 | .textTheme |
| 159 | .headlineSmall |
| 160 | ?.copyWith(color: MobileHomeMenu.ink)), |
| 161 | const SizedBox(height: 20), |
| 162 | Card( |
| 163 | child: Padding( |
| 164 | padding: const EdgeInsets.all(16), |
| 165 | child: Column( |
| 166 | crossAxisAlignment: CrossAxisAlignment.start, |
| 167 | children: [ |
| 168 | const Text('زمان و برنامه'), |
| 169 | const SizedBox(height: 8), |
| 170 | Text(widget.dateLabel(item['starts_at'] ?? |
| 171 | item['startsAt'] ?? |
| 172 | item['due_at'] ?? |
| 173 | item['dueAt'])), |
| 174 | if (item['ends_at'] != null || |
| 175 | item['endsAt'] != null) |
| 176 | Text( |
| 177 | 'پایان: ${widget.dateLabel(item['ends_at'] ?? item['endsAt'])}'), |
| 178 | Text(minutes > 0 |
| 179 | ? '$minutes دقیقه زمان برنامهریزیشده' |
| 180 | : 'زمان مطالعه تعیین نشده است'), |
| 181 | ]))), |
| 182 | Card( |
| 183 | child: ListTile( |
| 184 | leading: const Icon(Icons.shield_outlined), |
| 185 | title: const Text('با چه کسی به اشتراک گذاشته شده؟'), |
| 186 | subtitle: Text(visibility))), |
| 187 | if (item['notes'] is String && |
| 188 | (item['notes'] as String).isNotEmpty) |
| 189 | Card( |
| 190 | child: Padding( |
| 191 | padding: const EdgeInsets.all(16), |
| 192 | child: Text(item['notes'] as String))), |
| 193 | Card( |
| 194 | color: pending ? const Color(0xFFFFF1D9) : null, |
| 195 | child: ListTile( |
| 196 | leading: Icon( |
| 197 | pending ? Icons.sync : Icons.cloud_done_outlined), |
| 198 | title: Text(pending |
| 199 | ? 'در انتظار تأیید سرور' |
| 200 | : acknowledged |
| 201 | ? 'توسط سرور تأیید شد' |
| 202 | : widget.offline |
| 203 | ? 'نسخه ذخیرهشده؛ داده زنده نیست' |
| 204 | : 'آخرین دریافت از برنامه'), |
| 205 | subtitle: const Text( |
| 206 | 'این صفحه وضعیت رکورد انتخابشده است؛ برای دریافت تغییرات دستگاه دیگر به فهرست برگرد و تازهسازی کن.'))), |
| 207 | if (error != null) |
| 208 | Padding( |
| 209 | padding: const EdgeInsets.all(12), |
| 210 | child: Text(error!, |
| 211 | style: TextStyle( |
| 212 | color: Theme.of(context).colorScheme.error))), |
| 213 | if (!widget.canEdit) |
| 214 | const Text( |
| 215 | 'فقط مشاهده؛ ویرایش و ثبت زمان برای مالک این کار است.'), |
| 216 | if (widget.canEdit) ...[ |
| 217 | if (widget.canStudy && !pending && status != 'completed') |
| 218 | FilledButton.icon( |
| 219 | key: const ValueKey('detail-study'), |
| 220 | onPressed: busy ? null : () => act('study'), |
| 221 | icon: const Icon(Icons.play_arrow_outlined), |
| 222 | label: const Text('شروع مطالعه این تکلیف')), |
| 223 | if (status != 'completed') |
| 224 | FilledButton.icon( |
| 225 | key: const ValueKey('detail-complete'), |
| 226 | onPressed: busy ? null : () => act('complete'), |
| 227 | icon: const Icon(Icons.check), |
| 228 | label: const Text('انجام شد')), |
| 229 | OutlinedButton.icon( |
| 230 | key: const ValueKey('detail-edit'), |
| 231 | onPressed: busy ? null : () => act('edit'), |
| 232 | icon: const Icon(Icons.edit_outlined), |
| 233 | label: const Text('ویرایش تکلیف')), |
| 234 | TextButton.icon( |
| 235 | key: const ValueKey('detail-archive'), |
| 236 | onPressed: busy ? null : () => act('archive'), |
| 237 | icon: const Icon(Icons.archive_outlined), |
| 238 | label: const Text('بایگانی')), |
| 239 | ], |
| 240 | if (busy && pendingAction == 'complete') |
| 241 | const Center(child: CircularProgressIndicator()), |
| 242 | ])))); |
| 243 | } |
| 244 | } |