LifeMate — Personal, Family & Learning Companion
feat: add guardian family guidance conversation
davoodmehraban89 committed
Oct 5, 2026 at 16:24 UTC
74d360a54d98892a384631a530f3f23aedf65b94
1 file changed
+97
-1
apps/lifemate/lib/phase3_ui.dart
+97
-1
@@ -661,6 +661,87 @@ class _FamilyDashboardCardState extends State<FamilyDashboardCard> {
661
members = widget.api.listFamilyMembers(widget.family['id'].toString());
662
}
663
664
+ Future<void> openFamilyGuidance(
665
+ String familyId,
666
+ String childId,
667
+ String childName,
668
+ ) async {
669
+ final question = TextEditingController();
670
+ String? advice;
671
+ bool busy = false;
672
+ await showDialog<void>(
673
+ context: context,
674
+ builder: (dialogContext) => StatefulBuilder(
675
+ builder: (context, setLocalState) => AlertDialog(
676
+ title: Text('مشورت درباره $childName'),
677
+ content: SizedBox(
678
+ width: 520,
679
+ child: Column(
680
+ mainAxisSize: MainAxisSize.min,
681
+ children: [
682
+ const Text(
683
+ 'راهنما فقط از خلاصههای مجاز استفاده میکند و متن خصوصی فرزند را نمیبیند.',
684
+ ),
685
+ const SizedBox(height: 12),
686
+ TextField(
687
+ controller: question,
688
+ maxLines: 4,
689
+ decoration: const InputDecoration(
690
+ labelText: 'سؤال شما',
691
+ hintText: 'مثلاً چطور بدون فشار درباره امتحانها با او صحبت کنم؟',
692
+ ),
693
+ ),
694
+ if (advice != null) ...[
695
+ const SizedBox(height: 14),
696
+ Align(
697
+ alignment: Alignment.centerRight,
698
+ child: Text(
699
+ advice!,
700
+ style: Theme.of(context).textTheme.bodyLarge,
701
+ ),
702
+ ),
703
+ ],
704
+ ],
705
+ ),
706
+ ),
707
+ actions: [
708
+ TextButton(
709
+ onPressed: busy ? null : () => Navigator.pop(dialogContext),
710
+ child: const Text('بستن'),
711
+ ),
712
+ FilledButton(
713
+ onPressed: busy
714
+ ? null
715
+ : () async {
716
+ if (question.text.trim().isEmpty) return;
717
+ setLocalState(() => busy = true);
718
+ try {
719
+ final result = await widget.api.requestFamilyGuidance(
720
+ familyId,
721
+ childId,
722
+ question.text.trim(),
723
+ );
724
+ setLocalState(() {
725
+ advice = result['advice']?.toString() ??
726
+ 'پیشنهادی دریافت نشد.';
727
+ });
728
+ } catch (_) {
729
+ setLocalState(() {
730
+ advice = 'دریافت راهنمایی انجام نشد. دوباره تلاش کنید.';
731
+ });
732
+ } finally {
733
+ setLocalState(() => busy = false);
734
+ }
735
+ },
736
+ child: Text(busy ? 'در حال بررسی...' : 'دریافت راهنمایی'),
737
+ ),
738
+ ],
739
+ ),
740
+ ),
741
+ );
742
+ question.dispose();
743
+ }
744
+
745
Future<void> openChild(Map<String, dynamic> child) async {
746
final familyId = widget.family['id'].toString();
747
final childId = child['user_id'].toString();
@@ -751,7 +832,22 @@ class _FamilyDashboardCardState extends State<FamilyDashboardCard> {
832
),
833
),
834
actions: [
754
- TextButton(onPressed: () => Navigator.pop(dialogContext), child: const Text('بستن')),
835
+ TextButton(
836
+ onPressed: () => Navigator.pop(dialogContext),
837
+ child: const Text('بستن'),
838
+ ),
839
+ FilledButton.icon(
840
+ onPressed: () {
841
+ Navigator.pop(dialogContext);
842
+ openFamilyGuidance(
843
+ familyId,
844
+ childId,
845
+ child['display_name']?.toString() ?? 'فرزند',
846
+ );
847
+ },
848
+ icon: const Icon(Icons.psychology_alt_outlined),
849
+ label: const Text('مشورت با راهنمای خانواده'),
850
+ ),
851
],
852
),
853
);