LifeMate — Personal, Family & Learning Companion
test/role-entry-apk
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_localizations/flutter_localizations.dart'; |
| 3 | import 'package:shared_preferences/shared_preferences.dart'; |
| 4 | |
| 5 | import 'api.dart'; |
| 6 | import 'main.dart' show HomeShell; |
| 7 | |
| 8 | void main() => runApp(const LifeGuideRoleTestApp()); |
| 9 | |
| 10 | class LifeGuideRoleTestApp extends StatelessWidget { |
| 11 | const LifeGuideRoleTestApp({super.key}); |
| 12 | |
| 13 | @override |
| 14 | Widget build(BuildContext context) => MaterialApp( |
| 15 | debugShowCheckedModeBanner: false, |
| 16 | locale: const Locale('fa'), |
| 17 | supportedLocales: const [Locale('fa'), Locale('en')], |
| 18 | localizationsDelegates: const [ |
| 19 | GlobalMaterialLocalizations.delegate, |
| 20 | GlobalWidgetsLocalizations.delegate, |
| 21 | GlobalCupertinoLocalizations.delegate, |
| 22 | ], |
| 23 | theme: ThemeData( |
| 24 | colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF4D86E8)), |
| 25 | scaffoldBackgroundColor: const Color(0xFFF8FAFD), |
| 26 | inputDecorationTheme: const InputDecorationTheme(border: OutlineInputBorder()), |
| 27 | useMaterial3: true, |
| 28 | ), |
| 29 | home: const Directionality(textDirection: TextDirection.rtl, child: RoleEntryGate()), |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | class LocalTestProfile { |
| 34 | const LocalTestProfile({required this.category, required this.displayName}); |
| 35 | final String category; |
| 36 | final String displayName; |
| 37 | } |
| 38 | |
| 39 | class LocalTestProfileStore { |
| 40 | static const _categoryKey = 'lifeguide.local_profile.category'; |
| 41 | static const _displayNameKey = 'lifeguide.local_profile.display_name'; |
| 42 | |
| 43 | Future<LocalTestProfile?> load() async { |
| 44 | final prefs = await SharedPreferences.getInstance(); |
| 45 | final category = prefs.getString(_categoryKey); |
| 46 | final displayName = prefs.getString(_displayNameKey); |
| 47 | if (category == null || displayName == null || displayName.trim().isEmpty) { |
| 48 | return null; |
| 49 | } |
| 50 | return LocalTestProfile(category: category, displayName: displayName); |
| 51 | } |
| 52 | |
| 53 | Future<void> save(LocalTestProfile profile) async { |
| 54 | final name = profile.displayName.trim(); |
| 55 | if (name.isEmpty) throw ArgumentError('displayName cannot be empty'); |
| 56 | final prefs = await SharedPreferences.getInstance(); |
| 57 | await prefs.setString(_categoryKey, profile.category); |
| 58 | await prefs.setString(_displayNameKey, name); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | class RoleEntryGate extends StatefulWidget { |
| 63 | const RoleEntryGate({super.key}); |
| 64 | |
| 65 | @override |
| 66 | State<RoleEntryGate> createState() => _RoleEntryGateState(); |
| 67 | } |
| 68 | |
| 69 | class _RoleEntryGateState extends State<RoleEntryGate> { |
| 70 | final store = LocalTestProfileStore(); |
| 71 | LocalTestProfile? profile; |
| 72 | bool loading = true; |
| 73 | |
| 74 | @override |
| 75 | void initState() { |
| 76 | super.initState(); |
| 77 | _load(); |
| 78 | } |
| 79 | |
| 80 | Future<void> _load() async { |
| 81 | final saved = await store.load(); |
| 82 | if (!mounted) return; |
| 83 | setState(() { |
| 84 | profile = saved; |
| 85 | loading = false; |
| 86 | }); |
| 87 | } |
| 88 | |
| 89 | void _openHome(LocalTestProfile value) { |
| 90 | final role = value.category == 'adult' ? 'parent_guardian' : 'teen_minor'; |
| 91 | Navigator.of(context).pushReplacement( |
| 92 | MaterialPageRoute( |
| 93 | builder: (_) => HomeShell( |
| 94 | api: LocalRoleTestApi( |
| 95 | role: role, |
| 96 | label: value.displayName, |
| 97 | category: value.category, |
| 98 | ), |
| 99 | ), |
| 100 | ), |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | @override |
| 105 | Widget build(BuildContext context) { |
| 106 | if (loading) { |
| 107 | return const Scaffold(body: Center(child: CircularProgressIndicator())); |
| 108 | } |
| 109 | if (profile != null) { |
| 110 | WidgetsBinding.instance.addPostFrameCallback((_) { |
| 111 | if (mounted) _openHome(profile!); |
| 112 | }); |
| 113 | return const Scaffold(body: SizedBox.shrink()); |
| 114 | } |
| 115 | return RoleEntryPage( |
| 116 | onComplete: (value) async { |
| 117 | await store.save(value); |
| 118 | if (mounted) _openHome(value); |
| 119 | }, |
| 120 | ); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | class RoleEntryPage extends StatelessWidget { |
| 125 | const RoleEntryPage({super.key, required this.onComplete}); |
| 126 | final Future<void> Function(LocalTestProfile profile) onComplete; |
| 127 | |
| 128 | Future<void> _choose(BuildContext context, String category, String fallbackName) async { |
| 129 | final controller = TextEditingController(text: fallbackName); |
| 130 | final name = await showDialog<String>( |
| 131 | context: context, |
| 132 | builder: (dialogContext) => AlertDialog( |
| 133 | title: const Text('اسم این پروفایل چیست؟'), |
| 134 | content: TextField( |
| 135 | controller: controller, |
| 136 | autofocus: true, |
| 137 | textInputAction: TextInputAction.done, |
| 138 | decoration: const InputDecoration(labelText: 'نام نمایشی'), |
| 139 | onSubmitted: (value) { |
| 140 | if (value.trim().isNotEmpty) Navigator.pop(dialogContext, value.trim()); |
| 141 | }, |
| 142 | ), |
| 143 | actions: [ |
| 144 | TextButton(onPressed: () => Navigator.pop(dialogContext), child: const Text('انصراف')), |
| 145 | FilledButton( |
| 146 | onPressed: () { |
| 147 | final value = controller.text.trim(); |
| 148 | if (value.isNotEmpty) Navigator.pop(dialogContext, value); |
| 149 | }, |
| 150 | child: const Text('ادامه'), |
| 151 | ), |
| 152 | ], |
| 153 | ), |
| 154 | ); |
| 155 | controller.dispose(); |
| 156 | if (name == null || name.trim().isEmpty) return; |
| 157 | await onComplete(LocalTestProfile(category: category, displayName: name.trim())); |
| 158 | } |
| 159 | |
| 160 | @override |
| 161 | Widget build(BuildContext context) => Scaffold( |
| 162 | body: SafeArea( |
| 163 | child: Center( |
| 164 | child: ConstrainedBox( |
| 165 | constraints: const BoxConstraints(maxWidth: 480), |
| 166 | child: ListView( |
| 167 | shrinkWrap: true, |
| 168 | padding: const EdgeInsets.all(28), |
| 169 | children: [ |
| 170 | const Icon(Icons.route_rounded, size: 72), |
| 171 | const SizedBox(height: 16), |
| 172 | const Text('Life Guide', textAlign: TextAlign.center, style: TextStyle(fontSize: 32, fontWeight: FontWeight.w700)), |
| 173 | const SizedBox(height: 8), |
| 174 | const Text('چه کسی وارد میشود؟', textAlign: TextAlign.center, style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600)), |
| 175 | const SizedBox(height: 8), |
| 176 | const Text('یکبار پروفایل را انتخاب و نامگذاری کن؛ دفعههای بعد مستقیم وارد فضای شخصی خودت میشوی.', textAlign: TextAlign.center), |
| 177 | const SizedBox(height: 28), |
| 178 | _RoleButton(icon: Icons.girl_rounded, title: 'فرزند دختر', subtitle: 'فضای شخصی و تحصیلی با تم دخترانه', onTap: () => _choose(context, 'girl_minor', 'آرام')), |
| 179 | const SizedBox(height: 12), |
| 180 | _RoleButton(icon: Icons.boy_rounded, title: 'فرزند پسر', subtitle: 'فضای شخصی و تحصیلی با تم پسرانه', onTap: () => _choose(context, 'boy_minor', 'فرزند')), |
| 181 | const SizedBox(height: 12), |
| 182 | _RoleButton(icon: Icons.person_rounded, title: 'بزرگسال', subtitle: 'فضای شخصی، خانواده و مدیریت', onTap: () => _choose(context, 'adult', 'بزرگسال')), |
| 183 | const SizedBox(height: 20), |
| 184 | const Text('نسخه آزمایشی: ورود ایمیل/رمز موقتاً غیرفعال است.', textAlign: TextAlign.center, style: TextStyle(fontSize: 12)), |
| 185 | ], |
| 186 | ), |
| 187 | ), |
| 188 | ), |
| 189 | ), |
| 190 | ); |
| 191 | } |
| 192 | |
| 193 | class _RoleButton extends StatelessWidget { |
| 194 | const _RoleButton({required this.icon, required this.title, required this.subtitle, required this.onTap}); |
| 195 | final IconData icon; |
| 196 | final String title; |
| 197 | final String subtitle; |
| 198 | final VoidCallback onTap; |
| 199 | @override |
| 200 | Widget build(BuildContext context) => Card( |
| 201 | child: ListTile( |
| 202 | contentPadding: const EdgeInsets.symmetric(horizontal: 18, vertical: 10), |
| 203 | leading: Icon(icon, size: 36), |
| 204 | title: Text(title, style: const TextStyle(fontWeight: FontWeight.w700)), |
| 205 | subtitle: Text(subtitle), |
| 206 | trailing: const Icon(Icons.chevron_left_rounded), |
| 207 | onTap: onTap, |
| 208 | ), |
| 209 | ); |
| 210 | } |
| 211 | |
| 212 | class LocalRoleTestApi implements IdentityApi { |
| 213 | LocalRoleTestApi({required this.role, required this.label, this.category}); |
| 214 | final String role; |
| 215 | final String label; |
| 216 | final String? category; |
| 217 | bool familyCreated = false; |
| 218 | String familyName = 'خانواده من'; |
| 219 | @override String? accessToken = 'local-role-test'; |
| 220 | @override Future<void> login(String email, String password) async {} |
| 221 | @override Future<void> register({required String displayName, required String email, required String password}) async {} |
| 222 | @override Future<void> verifyEmail(String token) async {} |
| 223 | @override Future<void> forgotPassword(String email) async {} |
| 224 | @override Future<void> resetPassword(String token, String newPassword) async {} |
| 225 | @override Future<void> changePassword(String currentPassword, String newPassword) async {} |
| 226 | @override Future<Map<String,dynamic>> getProfile() async => {'display_name': label, 'email_normalized':'test@lifeguide.local', 'user_id': role == 'teen_minor' ? 'student-test' : 'parent-test', 'theme_preference': category == 'girl_minor' ? 'girl_pink' : category == 'boy_minor' ? 'boy_blue' : 'adult_blue'}; |
| 227 | @override Future<Map<String,dynamic>> updateProfile({String? displayName,String? birthDate,String? themePreference}) async => {'display_name':displayName ?? label,'theme_preference':themePreference ?? 'adult_blue'}; |
| 228 | @override Future<List<Map<String,dynamic>>> listFamilies() async => familyCreated ? [{'id':'family-test','name':familyName,'role':role,'is_admin':role == 'parent_guardian'}] : []; |
| 229 | @override Future<List<Map<String,dynamic>>> listFamilyMembers(String familyId) async => []; |
| 230 | @override Future<Map<String,dynamic>> createFamily(String name,{String? role}) async { familyCreated=true; familyName=name; return {'id':'family-test','name':name}; } |
| 231 | @override Future<void> inviteMember({required String familyId,required String email,required String role,String? themePreference}) async {} |
| 232 | @override Future<void> acceptInvitation(String token) async {} |
| 233 | @override Future<void> setGuardian({required String familyId,required String guardianUserId,required String minorUserId}) async {} |
| 234 | @override Future<List<Map<String,dynamic>>> getToday({required DateTime from,required DateTime to}) async => []; |
| 235 | @override Future<List<Map<String,dynamic>>> listPlanItems({DateTime? from,DateTime? to,String? kind}) async => []; |
| 236 | @override Future<Map<String,dynamic>> createPlanItem(Map<String,dynamic> data) async => {'id':'new-plan',...data}; |
| 237 | @override Future<Map<String,dynamic>> updatePlanItem(String itemId,Map<String,dynamic> data) async => {'id':itemId,...data}; |
| 238 | @override Future<List<Map<String,dynamic>>> listLifeContexts() async => []; |
| 239 | @override Future<Map<String,dynamic>> createLifeContext({required String kind,required String title}) async => {'id':'ctx-1','kind':kind,'title':title}; |
| 240 | @override Future<Map<String,dynamic>> createAcademicYear(Map<String,dynamic> data) async => {'id':'year-1',...data}; |
| 241 | @override Future<Map<String,dynamic>> createAcademicTerm(String yearId,Map<String,dynamic> data) async => {'id':'term-1',...data}; |
| 242 | @override Future<Map<String,dynamic>> createSubject(String termId,Map<String,dynamic> data) async => {'id':'subject-1',...data}; |
| 243 | @override Future<Map<String,dynamic>> createClassSession(String subjectId,Map<String,dynamic> data) async => {'id':'class-1',...data}; |
| 244 | @override Future<Map<String,dynamic>> setGrade(String itemId,{required num points,required num outOf}) async => {'id':itemId}; |
| 245 | @override Future<List<Map<String,dynamic>>> claimDueReminders() async => []; |
| 246 | @override Future<Map<String,dynamic>> getSchoolOverview(String studentUserId) async => {'years':[],'subjects':[],'workload':[],'grades':[]}; |
| 247 | @override Future<List<Map<String,dynamic>>> getTimetable(String studentUserId) async => []; |
| 248 | @override Future<List<Map<String,dynamic>>> getFamilyCalendar(String familyId) async => []; |
| 249 | @override Future<Map<String,dynamic>> getChildSupportSummary(String familyId,String studentUserId) async => {'upcoming':[],'metrics':{}}; |
| 250 | @override Future<Map<String,dynamic>> submitSyncMutations(List<Map<String,dynamic>> mutations) async => {'results':[]}; |
| 251 | @override Future<Map<String,dynamic>> createLearningGoal({required String title,String? target,String? subjectId}) async => {'id':'goal-1','title':title}; |
| 252 | @override Future<List<Map<String,dynamic>>> listLearningGoals() async => []; |
| 253 | @override Future<Map<String,dynamic>> createLearningCheckin({String? learningGoalId,required int confidence,required int difficulty,String? note}) async => {'id':'checkin-1'}; |
| 254 | @override Future<Map<String,dynamic>> createWellbeingCheckin({required int mood,required int energy,required int stress,String? note,String visibility='private'}) async => {'id':'wellbeing-1'}; |
| 255 | @override Future<List<Map<String,dynamic>>> listWellbeingCheckins() async => []; |
| 256 | @override Future<Map<String,dynamic>> createAiSession(String kind) async => {'id':'session-1'}; |
| 257 | @override Future<Map<String,dynamic>> sendAiMessage(String sessionId,String message) async => {'id':'message-1','body':'پاسخ آزمایشی Life Guide'}; |
| 258 | @override Future<Map<String,dynamic>> getGuardianWellbeingSummary(String familyId,String minorUserId) async => {'summary':{},'safety':{},'rawNotesIncluded':false,'rawConversationIncluded':false}; |
| 259 | @override Future<Map<String,dynamic>> requestFamilyGuidance(String familyId,String minorUserId,String question) async => {'advice':'پیشنهاد آزمایشی','advisory':true,'medicalDiagnosis':false}; |
| 260 | } |