LifeMate — Personal, Family & Learning Companion
feat: provide distinct teen and parent authenticated shells
davoodmehraban89 committed
Oct 5, 2026 at 09:07 UTC
8ba7a8fc63397e23f3611a9b619fcb86b4f1343e
1 file changed
+114
-37
apps/lifemate/lib/main.dart
+114
-37
@@ -480,6 +480,7 @@ class SimpleFormPage extends StatelessWidget {
480
class HomeShell extends StatefulWidget {
481
const HomeShell({super.key, required this.api});
482
final IdentityApi api;
483
+
484
@override
485
State<HomeShell> createState() => _HomeShellState();
486
}
@@ -487,36 +488,108 @@ class HomeShell extends StatefulWidget {
488
class _HomeShellState extends State<HomeShell> {
489
int index = 0;
490
String themePreference = 'adult_blue';
490
- static const pages = [
491
+ bool adultShell = false;
492
+
493
+ static const studentPages = [
494
'امروز',
495
'برنامه هفتگی',
496
'تقویم',
497
'تکالیف و کارها',
498
'امتحانها و نمرات',
499
'تمرکز',
497
- 'همراه هوشمند'
500
+ 'همراه هوشمند',
501
+ ];
502
+
503
+ static const adultPages = [
504
+ 'امروز',
505
+ 'برنامهریز',
506
+ 'خانواده',
507
+ 'راهنما',
508
+ 'من',
509
];
510
511
@override
512
void initState() {
513
super.initState();
503
- loadTheme();
514
+ loadContext();
515
}
516
506
- Future<void> loadTheme() async {
517
+ Future<void> loadContext() async {
518
try {
519
final profile = await widget.api.getProfile();
520
+ final families = await widget.api.listFamilies();
521
+ final hasAdultRole = families.any(
522
+ (family) =>
523
+ family['role'] == 'parent_guardian' ||
524
+ family['role'] == 'adult_member',
525
+ );
526
if (mounted) {
510
- setState(() => themePreference =
511
- profile['theme_preference']?.toString() ?? 'adult_blue');
527
+ setState(() {
528
+ themePreference =
529
+ profile['theme_preference']?.toString() ?? 'adult_blue';
530
+ adultShell = hasAdultRole;
531
+ index = 0;
532
+ });
533
}
534
} catch (_) {}
535
}
536
537
+ List<String> get pages => adultShell ? adultPages : studentPages;
538
+
539
Color get accent => themePreference == 'girl_pink'
540
? const Color(0xFFE58FB0)
541
: const Color(0xFF4D86E8);
542
543
+ List<NavigationDestination> get destinations => adultShell
544
+ ? const [
545
+ NavigationDestination(
546
+ icon: Icon(Icons.home_outlined),
547
+ label: 'امروز',
548
+ ),
549
+ NavigationDestination(
550
+ icon: Icon(Icons.event_note_outlined),
551
+ label: 'برنامهریز',
552
+ ),
553
+ NavigationDestination(
554
+ icon: Icon(Icons.family_restroom_outlined),
555
+ label: 'خانواده',
556
+ ),
557
+ NavigationDestination(
558
+ icon: Icon(Icons.assistant_outlined),
559
+ label: 'راهنما',
560
+ ),
561
+ NavigationDestination(
562
+ icon: Icon(Icons.person_outline),
563
+ label: 'من',
564
+ ),
565
+ ]
566
+ : const [
567
+ NavigationDestination(
568
+ icon: Icon(Icons.home_outlined),
569
+ label: 'امروز',
570
+ ),
571
+ NavigationDestination(
572
+ icon: Icon(Icons.schedule_outlined),
573
+ label: 'برنامه',
574
+ ),
575
+ NavigationDestination(
576
+ icon: Icon(Icons.calendar_month_outlined),
577
+ label: 'تقویم',
578
+ ),
579
+ NavigationDestination(
580
+ icon: Icon(Icons.task_alt_outlined),
581
+ label: 'کارها',
582
+ ),
583
+ NavigationDestination(
584
+ icon: Icon(Icons.school_outlined),
585
+ label: 'امتحانها',
586
+ ),
587
+ ];
588
+
589
+ void selectPage(int next) {
590
+ setState(() => index = next);
591
+ }
592
+
593
@override
594
Widget build(BuildContext context) => Theme(
595
data: Theme.of(context).copyWith(
@@ -528,51 +601,55 @@ class _HomeShellState extends State<HomeShell> {
601
title: Text(pages[index]),
602
actions: [
603
IconButton(
531
- onPressed: () => Navigator.of(context).push(MaterialPageRoute(
532
- builder: (_) => ProfileFamilyPage(api: widget.api))),
604
+ onPressed: () => Navigator.of(context).push(
605
+ MaterialPageRoute(
606
+ builder: (_) => ProfileFamilyPage(api: widget.api),
607
+ ),
608
+ ),
609
icon: const Icon(Icons.person_outline),
610
),
611
],
612
),
613
body: Center(
538
- child: Text(pages[index],
539
- style: Theme.of(context).textTheme.headlineMedium)),
614
+ child: Text(
615
+ pages[index],
616
+ style: Theme.of(context).textTheme.headlineMedium,
617
+ ),
618
+ ),
619
bottomNavigationBar: NavigationBar(
620
selectedIndex: index > 4 ? 0 : index,
542
- onDestinationSelected: (i) => setState(() => index = i),
543
- destinations: const [
544
- NavigationDestination(
545
- icon: Icon(Icons.home_outlined), label: 'امروز'),
546
- NavigationDestination(
547
- icon: Icon(Icons.schedule_outlined), label: 'برنامه'),
548
- NavigationDestination(
549
- icon: Icon(Icons.calendar_month_outlined), label: 'تقویم'),
550
- NavigationDestination(
551
- icon: Icon(Icons.task_alt_outlined), label: 'کارها'),
552
- NavigationDestination(
553
- icon: Icon(Icons.school_outlined), label: 'امتحانها'),
554
- ],
621
+ onDestinationSelected: selectPage,
622
+ destinations: destinations,
623
),
624
drawer: Drawer(
625
child: SafeArea(
626
child: ListView(
627
children: [
628
const ListTile(
561
- title: Text('LifeMate'), subtitle: Text('منوی اصلی')),
562
- ...pages.asMap().entries.map((entry) => ListTile(
563
- title: Text(entry.value),
564
- onTap: () {
565
- setState(() => index = entry.key);
566
- Navigator.pop(context);
567
- },
568
- )),
569
- const Divider(),
570
- ListTile(
571
- leading: const Icon(Icons.family_restroom),
572
- title: const Text('خانواده'),
573
- onTap: () => Navigator.of(context).push(MaterialPageRoute(
574
- builder: (_) => ProfileFamilyPage(api: widget.api))),
629
+ title: Text('LifeMate'),
630
+ subtitle: Text('منوی اصلی'),
631
),
632
+ ...pages.asMap().entries.map(
633
+ (entry) => ListTile(
634
+ title: Text(entry.value),
635
+ onTap: () {
636
+ selectPage(entry.key);
637
+ Navigator.pop(context);
638
+ },
639
+ ),
640
+ ),
641
+ if (!adultShell) ...[
642
+ const Divider(),
643
+ ListTile(
644
+ leading: const Icon(Icons.family_restroom),
645
+ title: const Text('خانواده'),
646
+ onTap: () => Navigator.of(context).push(
647
+ MaterialPageRoute(
648
+ builder: (_) => ProfileFamilyPage(api: widget.api),
649
+ ),
650
+ ),
651
+ ),
652
+ ],
653
],
654
),
655
),