LifeMate — Personal, Family & Learning Companion
feat/aparat-learning-library
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 'api.dart'; |
| 3 | import 'phase3_ui.dart'; |
| 4 | |
| 5 | String iranStageLabel(int grade) => grade <= 3 |
| 6 | ? 'دوره اول ابتدایی' |
| 7 | : grade <= 6 |
| 8 | ? 'دوره دوم ابتدایی' |
| 9 | : grade <= 9 |
| 10 | ? 'دوره اول متوسطه' |
| 11 | : 'دوره دوم متوسطه'; |
| 12 | int iranLocalYear(int grade) => grade <= 3 |
| 13 | ? grade |
| 14 | : grade <= 6 |
| 15 | ? grade - 3 |
| 16 | : grade <= 9 |
| 17 | ? grade - 6 |
| 18 | : grade - 9; |
| 19 | |
| 20 | class IranianFamilyLearningHub extends StatefulWidget { |
| 21 | const IranianFamilyLearningHub({super.key, required this.identity}); |
| 22 | final IdentityApi identity; |
| 23 | @override |
| 24 | State<IranianFamilyLearningHub> createState() => _IranHubState(); |
| 25 | } |
| 26 | |
| 27 | class _IranHubState extends State<IranianFamilyLearningHub> { |
| 28 | int grade = 7; |
| 29 | String persona = 'child', sex = 'unspecified'; |
| 30 | final birth = TextEditingController(); |
| 31 | late Future<List<Map<String, dynamic>>> data; |
| 32 | bool busy = false, profileLoaded = false; |
| 33 | String? error; |
| 34 | Future<Map<String, dynamic>> request(String method, String path, |
| 35 | {Map<String, dynamic>? body}) { |
| 36 | final api = widget.identity; |
| 37 | if (api is! HttpIdentityApi) { |
| 38 | throw const ApiException(503, 'configured_api_required'); |
| 39 | } |
| 40 | return api.requestJson(method, path, body: body); |
| 41 | } |
| 42 | |
| 43 | @override |
| 44 | void initState() { |
| 45 | super.initState(); |
| 46 | data = load(); |
| 47 | } |
| 48 | |
| 49 | @override |
| 50 | void dispose() { |
| 51 | birth.dispose(); |
| 52 | super.dispose(); |
| 53 | } |
| 54 | |
| 55 | Future<List<Map<String, dynamic>>> load() async { |
| 56 | final profile = await request('GET', '/v1/me/iran-profile'); |
| 57 | if (!profileLoaded) { |
| 58 | final row = profile['profile'] as Map? ?? profile; |
| 59 | persona = row['household_persona']?.toString() ?? |
| 60 | row['householdPersona']?.toString() ?? |
| 61 | persona; |
| 62 | sex = row['sex']?.toString() ?? sex; |
| 63 | birth.text = |
| 64 | row['birth_date']?.toString() ?? row['birthDate']?.toString() ?? ''; |
| 65 | profileLoaded = true; |
| 66 | } |
| 67 | return [ |
| 68 | profile, |
| 69 | await request( |
| 70 | 'GET', '/v1/education/catalog?grade=$grade&schoolYear=1405-1406'), |
| 71 | await request('GET', '/v1/calendar/iran?year=1405'), |
| 72 | await request('GET', '/v1/me/notification-preferences') |
| 73 | ]; |
| 74 | } |
| 75 | |
| 76 | void reload() { |
| 77 | setState(() { |
| 78 | data = load(); |
| 79 | }); |
| 80 | } |
| 81 | |
| 82 | Future<void> mutate(Future<void> Function() action) async { |
| 83 | if (busy) return; |
| 84 | setState(() { |
| 85 | busy = true; |
| 86 | error = null; |
| 87 | }); |
| 88 | try { |
| 89 | await action(); |
| 90 | if (mounted) { |
| 91 | reload(); |
| 92 | ScaffoldMessenger.of(context).showSnackBar( |
| 93 | const SnackBar(content: Text('سرور تغییر را تأیید کرد.'))); |
| 94 | } |
| 95 | } catch (e) { |
| 96 | if (mounted) setState(() => error = uiErrorText(e)); |
| 97 | } finally { |
| 98 | if (mounted) setState(() => busy = false); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | Future<void> save() => mutate(() async { |
| 103 | await request('PATCH', '/v1/me/iran-profile', body: { |
| 104 | 'householdPersona': persona, |
| 105 | 'sex': sex, |
| 106 | 'birthDate': birth.text.trim().isEmpty ? null : birth.text.trim() |
| 107 | }); |
| 108 | if (persona == 'child') { |
| 109 | await request('PUT', '/v1/me/education', |
| 110 | body: {'nationalGrade': grade, 'schoolYear': '1405-1406'}); |
| 111 | } |
| 112 | }); |
| 113 | Future<void> preference(String key, bool value) => mutate(() async { |
| 114 | await request('PATCH', '/v1/me/notification-preferences', |
| 115 | body: {key: value}); |
| 116 | }); |
| 117 | @override |
| 118 | Widget build(BuildContext context) => Scaffold( |
| 119 | appBar: AppBar(title: const Text('خانواده و یادگیری ایران')), |
| 120 | body: FutureBuilder<List<Map<String, dynamic>>>( |
| 121 | future: data, |
| 122 | builder: (context, s) { |
| 123 | if (s.hasError) return LoadError(error: s.error!, retry: reload); |
| 124 | if (!s.hasData) { |
| 125 | return const Center(child: CircularProgressIndicator()); |
| 126 | } |
| 127 | final prefs = s.data![3]['preferences'] as Map? ?? s.data![3]; |
| 128 | final catalog = s.data![1]['subjects'] as List? ?? []; |
| 129 | final events = s.data![2]['events'] as List? ?? []; |
| 130 | return ListView(padding: const EdgeInsets.all(16), children: [ |
| 131 | if (busy) const LinearProgressIndicator(), |
| 132 | if (error != null) |
| 133 | Text(error!, |
| 134 | style: |
| 135 | TextStyle(color: Theme.of(context).colorScheme.error)), |
| 136 | Text('پروفایل ایرانی', |
| 137 | style: Theme.of(context).textTheme.titleLarge), |
| 138 | const Text( |
| 139 | 'این انتخاب، نقش خانواده یا دسترسی سرپرستی ایجاد نمیکند.'), |
| 140 | DropdownButtonFormField<String>( |
| 141 | initialValue: persona, |
| 142 | decoration: const InputDecoration(labelText: 'نقش نمایشی'), |
| 143 | items: const [ |
| 144 | DropdownMenuItem(value: 'mother', child: Text('مادر')), |
| 145 | DropdownMenuItem(value: 'father', child: Text('پدر')), |
| 146 | DropdownMenuItem(value: 'child', child: Text('فرزند')), |
| 147 | DropdownMenuItem(value: 'adult', child: Text('بزرگسال')) |
| 148 | ], |
| 149 | onChanged: busy |
| 150 | ? null |
| 151 | : (v) => setState(() => persona = v ?? persona)), |
| 152 | DropdownButtonFormField<String>( |
| 153 | initialValue: sex, |
| 154 | decoration: const InputDecoration(labelText: 'جنسیت'), |
| 155 | items: const [ |
| 156 | DropdownMenuItem(value: 'female', child: Text('دختر / زن')), |
| 157 | DropdownMenuItem(value: 'male', child: Text('پسر / مرد')), |
| 158 | DropdownMenuItem( |
| 159 | value: 'unspecified', child: Text('ذکر نشود')) |
| 160 | ], |
| 161 | onChanged: |
| 162 | busy ? null : (v) => setState(() => sex = v ?? sex)), |
| 163 | TextField( |
| 164 | controller: birth, |
| 165 | enabled: !busy, |
| 166 | decoration: const InputDecoration( |
| 167 | labelText: 'تاریخ تولد (YYYY-MM-DD)')), |
| 168 | if (persona == 'child') |
| 169 | DropdownButtonFormField<int>( |
| 170 | initialValue: grade, |
| 171 | decoration: const InputDecoration(labelText: 'پایه تحصیلی'), |
| 172 | items: [ |
| 173 | for (var g = 1; g <= 12; g++) |
| 174 | DropdownMenuItem( |
| 175 | value: g, |
| 176 | child: Text( |
| 177 | 'پایه $g — ${iranStageLabel(g)}، سال ${iranLocalYear(g)}')) |
| 178 | ], |
| 179 | onChanged: busy |
| 180 | ? null |
| 181 | : (v) { |
| 182 | setState(() => grade = v ?? grade); |
| 183 | reload(); |
| 184 | }), |
| 185 | FilledButton( |
| 186 | onPressed: busy ? null : save, |
| 187 | child: const Text('ذخیره پروفایل')), |
| 188 | const Divider(), |
| 189 | Text('کتابها و درسها', |
| 190 | style: Theme.of(context).textTheme.titleLarge), |
| 191 | const Text( |
| 192 | 'منبع رسمی کتابها لینک میشود؛ PDF بدون مجوز بازتوزیع بستهبندی نمیشود. اعتبار هر منبع نیازمند بررسی ناشر است.'), |
| 193 | ...catalog.map((raw) { |
| 194 | final r = raw as Map; |
| 195 | return ListTile( |
| 196 | leading: const Icon(Icons.menu_book_outlined), |
| 197 | title: Text(r['name_fa']?.toString() ?? ''), |
| 198 | subtitle: |
| 199 | SelectableText(r['source_url']?.toString() ?? '')); |
| 200 | }), |
| 201 | const Divider(), |
| 202 | Text('تقویم جلالی ۱۴۰۵', |
| 203 | style: Theme.of(context).textTheme.titleLarge), |
| 204 | const Text( |
| 205 | 'هفته از شنبه آغاز میشود؛ پنجشنبه و جمعه آخرهفته پیشفرضاند.'), |
| 206 | ...events.take(40).map((raw) { |
| 207 | final r = raw as Map; |
| 208 | return ListTile( |
| 209 | leading: Icon(r['is_official_holiday'] == true |
| 210 | ? Icons.event_busy_outlined |
| 211 | : Icons.event_outlined), |
| 212 | title: Text(r['title_fa']?.toString() ?? ''), |
| 213 | subtitle: Text('${r['jalali_month']}/${r['jalali_day']}')); |
| 214 | }), |
| 215 | const Divider(), |
| 216 | Text('یادآوری و اعلان', |
| 217 | style: Theme.of(context).textTheme.titleLarge), |
| 218 | for (final entry in { |
| 219 | 'inAppBanner': 'بنر داخل برنامه', |
| 220 | 'schoolReminders': 'یادآوری مدرسه', |
| 221 | 'calendarReminders': 'یادآوری تقویم' |
| 222 | }.entries) |
| 223 | SwitchListTile( |
| 224 | title: Text(entry.value), |
| 225 | value: prefs[switch (entry.key) { |
| 226 | 'inAppBanner' => 'in_app_banner', |
| 227 | 'schoolReminders' => 'school_reminders', |
| 228 | _ => 'calendar_reminders' |
| 229 | }] == |
| 230 | true, |
| 231 | onChanged: busy ? null : (v) => preference(entry.key, v)), |
| 232 | const Divider(), |
| 233 | const Text( |
| 234 | 'قابلیتهای سلامت، چرخه شخصی و راهنمای هوشمند در این مرحله فعال نیستند.'), |
| 235 | ]); |
| 236 | })); |
| 237 | } |