LifeMate — Personal, Family & Learning Companion
fix: stabilize identity family and guardian Flutter flows
davoodmehraban89 committed
Oct 5, 2026 at 08:39 UTC
d07a942329df6f6285097547b98bb2b75aac989a
1 file changed
+536
-500
apps/lifemate/lib/main.dart
+536
-500
@@ -11,7 +11,6 @@ class LifeMateApp extends StatelessWidget {
11
12
@override
13
Widget build(BuildContext context) {
14
- const accent = Color(0xFF4D86E8);
14
final uri = Uri.base;
15
final token = uri.queryParameters['token'];
16
Widget entry = SignInPage(
@@ -24,7 +23,6 @@ class LifeMateApp extends StatelessWidget {
23
} else if (token != null && uri.path.contains('reset-password')) {
24
entry = ResetPasswordPage(api: api, token: token);
25
}
27
-
26
return MaterialApp(
27
debugShowCheckedModeBanner: false,
28
locale: const Locale('fa'),
@@ -35,9 +33,10 @@ class LifeMateApp extends StatelessWidget {
33
GlobalCupertinoLocalizations.delegate,
34
],
35
theme: ThemeData(
38
- colorScheme: ColorScheme.fromSeed(seedColor: accent, surface: Colors.white),
36
+ colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF4D86E8)),
37
scaffoldBackgroundColor: const Color(0xFFF8FAFD),
40
- inputDecorationTheme: const InputDecorationTheme(border: OutlineInputBorder()),
38
+ inputDecorationTheme:
39
+ const InputDecorationTheme(border: OutlineInputBorder()),
40
useMaterial3: true,
41
),
42
home: Directionality(textDirection: TextDirection.rtl, child: entry),
@@ -68,11 +67,7 @@ String errorText(Object error) {
67
}
68
69
class SignInPage extends StatefulWidget {
71
- const SignInPage({
72
- super.key,
73
- required this.api,
74
- this.invitationToken,
75
- });
70
+ const SignInPage({super.key, required this.api, this.invitationToken});
71
final IdentityApi api;
72
final String? invitationToken;
73
@override
@@ -85,151 +80,98 @@ class _SignInPageState extends State<SignInPage> {
80
bool busy = false;
81
String? error;
82
88
- @override
89
- void dispose() {
90
- email.dispose();
91
- password.dispose();
92
- super.dispose();
93
- }
94
-
83
Future<void> submit() async {
96
- setState(() { busy = true; error = null; });
84
+ setState(() {
85
+ busy = true;
86
+ error = null;
87
+ });
88
try {
89
await widget.api.login(email.text, password.text);
90
if (widget.invitationToken != null) {
91
await widget.api.acceptInvitation(widget.invitationToken!);
92
}
102
- if (!mounted) {
103
- return;
104
- }
93
+ if (!mounted) return;
94
Navigator.of(context).pushReplacement(
95
MaterialPageRoute(builder: (_) => HomeShell(api: widget.api)),
96
);
97
} catch (e) {
109
- if (mounted) {
110
- setState(() => error = errorText(e));
111
- }
98
+ if (mounted) setState(() => error = errorText(e));
99
} finally {
113
- if (mounted) {
114
- setState(() => busy = false);
115
- }
100
+ if (mounted) setState(() => busy = false);
101
}
102
}
103
119
- Future<void> editProfile(Map<String, dynamic> profile) async {
120
- final name = TextEditingController(
121
- text: profile['display_name']?.toString() ?? '',
122
- );
123
- final theme = ValueNotifier<String>(
124
- profile['theme_preference']?.toString() ?? 'adult_blue',
125
- );
126
- final saved = await showDialog<bool>(
127
- context: context,
128
- builder: (dialogContext) => AlertDialog(
129
- title: const Text('ویرایش پروفایل'),
130
- content: Column(
131
- mainAxisSize: MainAxisSize.min,
132
- children: [
133
- TextField(
134
- controller: name,
135
- decoration: const InputDecoration(labelText: 'نام'),
136
- ),
137
- const SizedBox(height: 12),
138
- ValueListenableBuilder<String>(
139
- valueListenable: theme,
140
- builder: (_, value, __) => DropdownButtonFormField<String>(
141
- initialValue: value,
142
- decoration: const InputDecoration(labelText: 'تم'),
143
- items: const [
144
- DropdownMenuItem(
145
- value: 'girl_pink',
146
- child: Text('سفید / صورتی'),
104
+ @override
105
+ Widget build(BuildContext context) => Scaffold(
106
+ body: SafeArea(
107
+ child: Center(
108
+ child: ConstrainedBox(
109
+ constraints: const BoxConstraints(maxWidth: 440),
110
+ child: ListView(
111
+ padding: const EdgeInsets.all(28),
112
+ shrinkWrap: true,
113
+ children: [
114
+ const Icon(Icons.route_rounded, size: 64),
115
+ const SizedBox(height: 16),
116
+ const Text('LifeMate',
117
+ textAlign: TextAlign.center,
118
+ style:
119
+ TextStyle(fontSize: 32, fontWeight: FontWeight.w700)),
120
+ const Text('همراه شخصی، تحصیلی و خانوادگی',
121
+ textAlign: TextAlign.center),
122
+ const SizedBox(height: 28),
123
+ if (widget.invitationToken != null) ...[
124
+ const Card(
125
+ child: Padding(
126
+ padding: EdgeInsets.all(12),
127
+ child: Text(
128
+ 'برای قبول دعوت خانواده، با همان ایمیل دعوتشده وارد شو.'),
129
+ ),
130
+ ),
131
+ const SizedBox(height: 12),
132
+ ],
133
+ TextField(
134
+ controller: email,
135
+ keyboardType: TextInputType.emailAddress,
136
+ decoration: const InputDecoration(labelText: 'ایمیل'),
137
),
148
- DropdownMenuItem(
149
- value: 'boy_blue',
150
- child: Text('سفید / آبی نوجوان'),
138
+ const SizedBox(height: 12),
139
+ TextField(
140
+ controller: password,
141
+ obscureText: true,
142
+ decoration: const InputDecoration(labelText: 'رمز عبور'),
143
),
152
- DropdownMenuItem(
153
- value: 'adult_blue',
154
- child: Text('سفید / آبی بزرگسال'),
144
+ if (error != null) ...[
145
+ const SizedBox(height: 12),
146
+ Text(error!,
147
+ style: TextStyle(
148
+ color: Theme.of(context).colorScheme.error)),
149
+ ],
150
+ const SizedBox(height: 16),
151
+ FilledButton(
152
+ onPressed: busy ? null : submit,
153
+ child: Text(busy ? 'در حال ورود...' : 'ورود'),
154
+ ),
155
+ TextButton(
156
+ onPressed: busy
157
+ ? null
158
+ : () => Navigator.of(context).push(MaterialPageRoute(
159
+ builder: (_) => RecoveryPage(api: widget.api))),
160
+ child: const Text('رمز عبور را فراموش کردهام'),
161
+ ),
162
+ TextButton(
163
+ onPressed: busy
164
+ ? null
165
+ : () => Navigator.of(context).push(MaterialPageRoute(
166
+ builder: (_) => RegistrationPage(api: widget.api))),
167
+ child: const Text('ساخت حساب جدید'),
168
),
169
],
157
- onChanged: (v) {
158
- if (v != null) {
159
- theme.value = v;
160
- }
161
- },
170
),
171
),
164
- ],
165
- ),
166
- actions: [
167
- TextButton(
168
- onPressed: () => Navigator.pop(dialogContext, false),
169
- child: const Text('انصراف'),
170
- ),
171
- FilledButton(
172
- onPressed: () async {
173
- await widget.api.updateProfile(
174
- displayName: name.text.trim(),
175
- themePreference: theme.value,
176
- );
177
- if (dialogContext.mounted) {
178
- Navigator.pop(dialogContext, true);
179
- }
180
- },
181
- child: const Text('ذخیره'),
182
- ),
183
- ],
184
- ),
185
- );
186
- name.dispose();
187
- theme.dispose();
188
- if (saved == true && mounted) {
189
- setState(() => data = load());
190
- }
191
- }
192
-
193
- @override
194
- Widget build(BuildContext context) => Scaffold(
195
- body: SafeArea(
196
- child: Center(
197
- child: ConstrainedBox(
198
- constraints: const BoxConstraints(maxWidth: 440),
199
- child: ListView(
200
- padding: const EdgeInsets.all(28),
201
- shrinkWrap: true,
202
- children: [
203
- const Icon(Icons.route_rounded, size: 64),
204
- const SizedBox(height: 16),
205
- const Text('LifeMate', textAlign: TextAlign.center, style: TextStyle(fontSize: 32, fontWeight: FontWeight.w700)),
206
- const Text('همراه شخصی، تحصیلی و خانوادگی', textAlign: TextAlign.center),
207
- const SizedBox(height: 32),
208
- if (widget.invitationToken != null) ...[
209
- const Card(
210
- child: Padding(
211
- padding: EdgeInsets.all(12),
212
- child: Text(
213
- 'برای قبول دعوت خانواده، با همان ایمیلی که دعوت شده وارد شو.',
214
- ),
215
- ),
216
- ),
217
- const SizedBox(height: 12),
218
- ],
219
- TextField(controller: email, keyboardType: TextInputType.emailAddress, decoration: const InputDecoration(labelText: 'ایمیل')),
220
- const SizedBox(height: 12),
221
- TextField(controller: password, obscureText: true, decoration: const InputDecoration(labelText: 'رمز عبور')),
222
- if (error != null) Padding(padding: const EdgeInsets.only(top: 12), child: Text(error!, style: TextStyle(color: Theme.of(context).colorScheme.error))),
223
- const SizedBox(height: 16),
224
- FilledButton(onPressed: busy ? null : submit, child: Text(busy ? 'در حال ورود...' : 'ورود')),
225
- TextButton(onPressed: busy ? null : () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => RecoveryPage(api: widget.api))), child: const Text('رمز عبور را فراموش کردهام')),
226
- TextButton(onPressed: busy ? null : () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => RegistrationPage(api: widget.api))), child: const Text('ساخت حساب جدید')),
227
- ],
172
),
173
),
230
- ),
231
- ),
232
- );
174
+ );
175
}
176
177
class RegistrationPage extends StatefulWidget {
@@ -252,39 +194,50 @@ class _RegistrationPageState extends State<RegistrationPage> {
194
setState(() => error = 'تکرار رمز عبور یکسان نیست.');
195
return;
196
}
255
- setState(() { busy = true; error = null; });
197
+ setState(() {
198
+ busy = true;
199
+ error = null;
200
+ });
201
try {
257
- await widget.api.register(displayName: name.text, email: email.text, password: password.text);
258
- if (!mounted) {
259
- return;
260
- }
261
- ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('حساب ساخته شد. ایمیل تأیید را بررسی کن.')));
202
+ await widget.api.register(
203
+ displayName: name.text, email: email.text, password: password.text);
204
+ if (!mounted) return;
205
+ ScaffoldMessenger.of(context).showSnackBar(
206
+ const SnackBar(content: Text('حساب ساخته شد. ایمیل تأیید را بررسی کن.')),
207
+ );
208
Navigator.pop(context);
209
} catch (e) {
264
- if (mounted) {
265
- setState(() => error = errorText(e));
266
- }
210
+ if (mounted) setState(() => error = errorText(e));
211
} finally {
268
- if (mounted) {
269
- setState(() => busy = false);
270
- }
212
+ if (mounted) setState(() => busy = false);
213
}
214
}
215
216
@override
217
Widget build(BuildContext context) => SimpleFormPage(
276
- title: 'ساخت حساب',
277
- busy: busy,
278
- error: error,
279
- action: 'ثبتنام و ارسال ایمیل تأیید',
280
- onPressed: submit,
281
- fields: [
282
- TextField(controller: name, decoration: const InputDecoration(labelText: 'نام')),
283
- TextField(controller: email, keyboardType: TextInputType.emailAddress, decoration: const InputDecoration(labelText: 'ایمیل')),
284
- TextField(controller: password, obscureText: true, decoration: const InputDecoration(labelText: 'رمز عبور')),
285
- TextField(controller: confirm, obscureText: true, decoration: const InputDecoration(labelText: 'تکرار رمز عبور')),
286
- ],
287
- );
218
+ title: 'ساخت حساب',
219
+ busy: busy,
220
+ error: error,
221
+ action: 'ثبتنام و ارسال ایمیل تأیید',
222
+ onPressed: submit,
223
+ fields: [
224
+ TextField(
225
+ controller: name,
226
+ decoration: const InputDecoration(labelText: 'نام')),
227
+ TextField(
228
+ controller: email,
229
+ keyboardType: TextInputType.emailAddress,
230
+ decoration: const InputDecoration(labelText: 'ایمیل')),
231
+ TextField(
232
+ controller: password,
233
+ obscureText: true,
234
+ decoration: const InputDecoration(labelText: 'رمز عبور')),
235
+ TextField(
236
+ controller: confirm,
237
+ obscureText: true,
238
+ decoration: const InputDecoration(labelText: 'تکرار رمز عبور')),
239
+ ],
240
+ );
241
}
242
243
class RecoveryPage extends StatefulWidget {
@@ -297,39 +250,41 @@ class RecoveryPage extends StatefulWidget {
250
class _RecoveryPageState extends State<RecoveryPage> {
251
final email = TextEditingController();
252
bool busy = false;
300
- String? error;
253
bool sent = false;
254
+ String? error;
255
256
Future<void> submit() async {
304
- setState(() { busy = true; error = null; });
257
+ setState(() {
258
+ busy = true;
259
+ error = null;
260
+ });
261
try {
262
await widget.api.forgotPassword(email.text);
307
- if (mounted) {
308
- setState(() => sent = true);
309
- }
263
+ if (mounted) setState(() => sent = true);
264
} catch (e) {
311
- if (mounted) {
312
- setState(() => error = errorText(e));
313
- }
265
+ if (mounted) setState(() => error = errorText(e));
266
} finally {
315
- if (mounted) {
316
- setState(() => busy = false);
317
- }
267
+ if (mounted) setState(() => busy = false);
268
}
269
}
270
271
@override
272
Widget build(BuildContext context) => SimpleFormPage(
323
- title: 'بازیابی رمز عبور',
324
- busy: busy,
325
- error: error,
326
- action: sent ? 'لینک ارسال شد' : 'ارسال لینک بازیابی',
327
- onPressed: sent ? null : submit,
328
- fields: [
329
- TextField(controller: email, keyboardType: TextInputType.emailAddress, decoration: const InputDecoration(labelText: 'ایمیل تأییدشده')),
330
- if (sent) const Text('اگر حسابی با این ایمیل وجود داشته باشد، لینک بازیابی ارسال میشود.'),
331
- ],
332
- );
273
+ title: 'بازیابی رمز عبور',
274
+ busy: busy,
275
+ error: error,
276
+ action: sent ? 'لینک ارسال شد' : 'ارسال لینک بازیابی',
277
+ onPressed: sent ? null : submit,
278
+ fields: [
279
+ TextField(
280
+ controller: email,
281
+ keyboardType: TextInputType.emailAddress,
282
+ decoration: const InputDecoration(labelText: 'ایمیل تأییدشده')),
283
+ if (sent)
284
+ const Text(
285
+ 'اگر حسابی با این ایمیل وجود داشته باشد، لینک بازیابی ارسال میشود.'),
286
+ ],
287
+ );
288
}
289
290
class VerifyEmailPage extends StatefulWidget {
@@ -343,23 +298,23 @@ class VerifyEmailPage extends StatefulWidget {
298
class _VerifyEmailPageState extends State<VerifyEmailPage> {
299
String message = 'در حال تأیید ایمیل...';
300
@override
346
- void initState() { super.initState(); verify(); }
301
+ void initState() {
302
+ super.initState();
303
+ verify();
304
+ }
305
306
Future<void> verify() async {
307
try {
308
await widget.api.verifyEmail(widget.token);
351
- if (mounted) {
352
- setState(() => message = 'ایمیل با موفقیت تأیید شد.');
353
- }
309
+ if (mounted) setState(() => message = 'ایمیل با موفقیت تأیید شد.');
310
} catch (e) {
355
- if (mounted) {
356
- setState(() => message = errorText(e));
357
- }
311
+ if (mounted) setState(() => message = errorText(e));
312
}
313
}
314
315
@override
362
- Widget build(BuildContext context) => Scaffold(body: Center(child: Padding(padding: const EdgeInsets.all(24), child: Text(message))));
316
+ Widget build(BuildContext context) =>
317
+ Scaffold(body: Center(child: Text(message)));
318
}
319
320
class ResetPasswordPage extends StatefulWidget {
@@ -374,43 +329,46 @@ class _ResetPasswordPageState extends State<ResetPasswordPage> {
329
final password = TextEditingController();
330
final confirm = TextEditingController();
331
bool busy = false;
377
- String? error;
332
bool done = false;
333
+ String? error;
334
335
Future<void> submit() async {
336
if (password.text != confirm.text) {
337
setState(() => error = 'تکرار رمز عبور یکسان نیست.');
338
return;
339
}
385
- setState(() { busy = true; error = null; });
340
+ setState(() {
341
+ busy = true;
342
+ error = null;
343
+ });
344
try {
345
await widget.api.resetPassword(widget.token, password.text);
388
- if (mounted) {
389
- setState(() => done = true);
390
- }
346
+ if (mounted) setState(() => done = true);
347
} catch (e) {
392
- if (mounted) {
393
- setState(() => error = errorText(e));
394
- }
348
+ if (mounted) setState(() => error = errorText(e));
349
} finally {
396
- if (mounted) {
397
- setState(() => busy = false);
398
- }
350
+ if (mounted) setState(() => busy = false);
351
}
352
}
353
354
@override
355
Widget build(BuildContext context) => SimpleFormPage(
404
- title: 'ساخت رمز جدید',
405
- busy: busy,
406
- error: error,
407
- action: done ? 'رمز تغییر کرد' : 'ذخیره رمز جدید',
408
- onPressed: done ? null : submit,
409
- fields: [
410
- TextField(controller: password, obscureText: true, decoration: const InputDecoration(labelText: 'رمز جدید')),
411
- TextField(controller: confirm, obscureText: true, decoration: const InputDecoration(labelText: 'تکرار رمز جدید')),
412
- ],
413
- );
356
+ title: 'ساخت رمز جدید',
357
+ busy: busy,
358
+ error: error,
359
+ action: done ? 'رمز تغییر کرد' : 'ذخیره رمز جدید',
360
+ onPressed: done ? null : submit,
361
+ fields: [
362
+ TextField(
363
+ controller: password,
364
+ obscureText: true,
365
+ decoration: const InputDecoration(labelText: 'رمز جدید')),
366
+ TextField(
367
+ controller: confirm,
368
+ obscureText: true,
369
+ decoration: const InputDecoration(labelText: 'تکرار رمز جدید')),
370
+ ],
371
+ );
372
}
373
374
class ChangePasswordPage extends StatefulWidget {
@@ -432,42 +390,57 @@ class _ChangePasswordPageState extends State<ChangePasswordPage> {
390
setState(() => error = 'تکرار رمز عبور یکسان نیست.');
391
return;
392
}
435
- setState(() { busy = true; error = null; });
393
+ setState(() {
394
+ busy = true;
395
+ error = null;
396
+ });
397
try {
398
await widget.api.changePassword(current.text, next.text);
438
- if (!mounted) {
439
- return;
440
- }
441
- ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('رمز عبور تغییر کرد.')));
399
+ if (!mounted) return;
400
+ ScaffoldMessenger.of(context)
401
+ .showSnackBar(const SnackBar(content: Text('رمز عبور تغییر کرد.')));
402
Navigator.pop(context);
403
} catch (e) {
444
- if (mounted) {
445
- setState(() => error = errorText(e));
446
- }
404
+ if (mounted) setState(() => error = errorText(e));
405
} finally {
448
- if (mounted) {
449
- setState(() => busy = false);
450
- }
406
+ if (mounted) setState(() => busy = false);
407
}
408
}
409
410
@override
411
Widget build(BuildContext context) => SimpleFormPage(
456
- title: 'تغییر رمز عبور',
457
- busy: busy,
458
- error: error,
459
- action: 'ذخیره رمز جدید',
460
- onPressed: submit,
461
- fields: [
462
- TextField(controller: current, obscureText: true, decoration: const InputDecoration(labelText: 'رمز فعلی')),
463
- TextField(controller: next, obscureText: true, decoration: const InputDecoration(labelText: 'رمز جدید')),
464
- TextField(controller: confirm, obscureText: true, decoration: const InputDecoration(labelText: 'تکرار رمز جدید')),
465
- ],
466
- );
412
+ title: 'تغییر رمز عبور',
413
+ busy: busy,
414
+ error: error,
415
+ action: 'ذخیره رمز جدید',
416
+ onPressed: submit,
417
+ fields: [
418
+ TextField(
419
+ controller: current,
420
+ obscureText: true,
421
+ decoration: const InputDecoration(labelText: 'رمز فعلی')),
422
+ TextField(
423
+ controller: next,
424
+ obscureText: true,
425
+ decoration: const InputDecoration(labelText: 'رمز جدید')),
426
+ TextField(
427
+ controller: confirm,
428
+ obscureText: true,
429
+ decoration: const InputDecoration(labelText: 'تکرار رمز جدید')),
430
+ ],
431
+ );
432
}
433
434
class SimpleFormPage extends StatelessWidget {
470
- const SimpleFormPage({super.key, required this.title, required this.fields, required this.action, required this.onPressed, this.busy = false, this.error});
435
+ const SimpleFormPage({
436
+ super.key,
437
+ required this.title,
438
+ required this.fields,
439
+ required this.action,
440
+ required this.onPressed,
441
+ this.busy = false,
442
+ this.error,
443
+ });
444
final String title;
445
final List<Widget> fields;
446
final String action;
@@ -477,21 +450,31 @@ class SimpleFormPage extends StatelessWidget {
450
451
@override
452
Widget build(BuildContext context) => Scaffold(
480
- appBar: AppBar(title: Text(title)),
481
- body: Center(
482
- child: ConstrainedBox(
483
- constraints: const BoxConstraints(maxWidth: 520),
484
- child: ListView(
485
- padding: const EdgeInsets.all(24),
486
- children: [
487
- for (final field in fields) Padding(padding: const EdgeInsets.only(bottom: 12), child: field),
488
- if (error != null) Padding(padding: const EdgeInsets.only(bottom: 12), child: Text(error!, style: TextStyle(color: Theme.of(context).colorScheme.error))),
489
- FilledButton(onPressed: busy ? null : onPressed, child: Text(busy ? 'لطفاً صبر کن...' : action)),
490
- ],
453
+ appBar: AppBar(title: Text(title)),
454
+ body: Center(
455
+ child: ConstrainedBox(
456
+ constraints: const BoxConstraints(maxWidth: 520),
457
+ child: ListView(
458
+ padding: const EdgeInsets.all(24),
459
+ children: [
460
+ for (final field in fields)
461
+ Padding(
462
+ padding: const EdgeInsets.only(bottom: 12), child: field),
463
+ if (error != null)
464
+ Padding(
465
+ padding: const EdgeInsets.only(bottom: 12),
466
+ child: Text(error!,
467
+ style: TextStyle(
468
+ color: Theme.of(context).colorScheme.error)),
469
+ ),
470
+ FilledButton(
471
+ onPressed: busy ? null : onPressed,
472
+ child: Text(busy ? 'لطفاً صبر کن...' : action)),
473
+ ],
474
+ ),
475
+ ),
476
),
492
- ),
493
- ),
494
- );
477
+ );
478
}
479
480
class HomeShell extends StatefulWidget {
@@ -504,7 +487,15 @@ class HomeShell extends StatefulWidget {
487
class _HomeShellState extends State<HomeShell> {
488
int index = 0;
489
String themePreference = 'adult_blue';
507
- static const destinations = ['امروز', 'برنامه هفتگی', 'تقویم', 'تکالیف و کارها', 'امتحانها و نمرات', 'تمرکز', 'همراه هوشمند'];
490
+ static const pages = [
491
+ 'امروز',
492
+ 'برنامه هفتگی',
493
+ 'تقویم',
494
+ 'تکالیف و کارها',
495
+ 'امتحانها و نمرات',
496
+ 'تمرکز',
497
+ 'همراه هوشمند'
498
+ ];
499
500
@override
501
void initState() {
@@ -516,9 +507,8 @@ class _HomeShellState extends State<HomeShell> {
507
try {
508
final profile = await widget.api.getProfile();
509
if (mounted) {
519
- setState(() {
520
- themePreference = profile['theme_preference']?.toString() ?? 'adult_blue';
521
- });
510
+ setState(() => themePreference =
511
+ profile['theme_preference']?.toString() ?? 'adult_blue');
512
}
513
} catch (_) {}
514
}
@@ -529,53 +519,66 @@ class _HomeShellState extends State<HomeShell> {
519
520
@override
521
Widget build(BuildContext context) => Theme(
532
- data: Theme.of(context).copyWith(
533
- colorScheme: ColorScheme.fromSeed(
534
- seedColor: accent,
535
- surface: Colors.white,
536
- ),
537
- scaffoldBackgroundColor: Colors.white,
538
- ),
539
- child: Scaffold(
540
- appBar: AppBar(
541
- title: Text(destinations[index]),
542
- actions: [
543
- IconButton(
544
- onPressed: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => ProfileFamilyPage(api: widget.api))),
545
- icon: const Icon(Icons.person_outline),
522
+ data: Theme.of(context).copyWith(
523
+ colorScheme: ColorScheme.fromSeed(seedColor: accent),
524
+ scaffoldBackgroundColor: Colors.white,
525
),
547
- ],
548
- ),
549
- body: Center(child: Text(destinations[index], style: Theme.of(context).textTheme.headlineMedium)),
550
- bottomNavigationBar: NavigationBar(
551
- selectedIndex: index > 4 ? 0 : index,
552
- onDestinationSelected: (i) => setState(() => index = i),
553
- destinations: const [
554
- NavigationDestination(icon: Icon(Icons.home_outlined), label: 'امروز'),
555
- NavigationDestination(icon: Icon(Icons.schedule_outlined), label: 'برنامه'),
556
- NavigationDestination(icon: Icon(Icons.calendar_month_outlined), label: 'تقویم'),
557
- NavigationDestination(icon: Icon(Icons.task_alt_outlined), label: 'کارها'),
558
- NavigationDestination(icon: Icon(Icons.school_outlined), label: 'امتحانها'),
559
- ],
560
- ),
561
- drawer: Drawer(
562
- child: SafeArea(
563
- child: ListView(
564
- children: [
565
- const ListTile(title: Text('LifeMate'), subtitle: Text('منوی اصلی')),
566
- ...destinations.asMap().entries.map((e) => ListTile(title: Text(e.value), onTap: () { setState(() => index = e.key); Navigator.pop(context); })),
567
- const Divider(),
568
- ListTile(
569
- leading: const Icon(Icons.family_restroom),
570
- title: const Text('خانواده'),
571
- onTap: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => ProfileFamilyPage(api: widget.api))),
526
+ child: Scaffold(
527
+ appBar: AppBar(
528
+ title: Text(pages[index]),
529
+ actions: [
530
+ IconButton(
531
+ onPressed: () => Navigator.of(context).push(MaterialPageRoute(
532
+ builder: (_) => ProfileFamilyPage(api: widget.api))),
533
+ icon: const Icon(Icons.person_outline),
534
+ ),
535
+ ],
536
+ ),
537
+ body: Center(
538
+ child: Text(pages[index],
539
+ style: Theme.of(context).textTheme.headlineMedium)),
540
+ bottomNavigationBar: NavigationBar(
541
+ 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
+ ],
555
+ ),
556
+ drawer: Drawer(
557
+ child: SafeArea(
558
+ child: ListView(
559
+ children: [
560
+ 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))),
575
+ ),
576
+ ],
577
+ ),
578
),
573
- ],
579
+ ),
580
),
575
- ),
576
- ),
577
- ),
578
- );
581
+ );
582
}
583
584
class ProfileFamilyPage extends StatefulWidget {
@@ -588,9 +591,67 @@ class ProfileFamilyPage extends StatefulWidget {
591
class _ProfileFamilyPageState extends State<ProfileFamilyPage> {
592
late Future<List<dynamic>> data;
593
@override
591
- void initState() { super.initState(); data = load(); }
594
+ void initState() {
595
+ super.initState();
596
+ data = load();
597
+ }
598
593
- Future<List<dynamic>> load() async => [await widget.api.getProfile(), await widget.api.listFamilies()];
599
+ Future<List<dynamic>> load() async =>
600
+ [await widget.api.getProfile(), await widget.api.listFamilies()];
601
+
602
+ Future<void> editProfile(Map<String, dynamic> profile) async {
603
+ final name = TextEditingController(
604
+ text: profile['display_name']?.toString() ?? '');
605
+ final theme = ValueNotifier<String>(
606
+ profile['theme_preference']?.toString() ?? 'adult_blue');
607
+ final saved = await showDialog<bool>(
608
+ context: context,
609
+ builder: (dialogContext) => AlertDialog(
610
+ title: const Text('ویرایش پروفایل'),
611
+ content: Column(mainAxisSize: MainAxisSize.min, children: [
612
+ TextField(
613
+ controller: name,
614
+ decoration: const InputDecoration(labelText: 'نام')),
615
+ const SizedBox(height: 12),
616
+ ValueListenableBuilder<String>(
617
+ valueListenable: theme,
618
+ builder: (_, value, __) => DropdownButtonFormField<String>(
619
+ initialValue: value,
620
+ decoration: const InputDecoration(labelText: 'تم'),
621
+ items: const [
622
+ DropdownMenuItem(
623
+ value: 'girl_pink', child: Text('سفید / صورتی')),
624
+ DropdownMenuItem(
625
+ value: 'boy_blue', child: Text('سفید / آبی نوجوان')),
626
+ DropdownMenuItem(
627
+ value: 'adult_blue', child: Text('سفید / آبی بزرگسال')),
628
+ ],
629
+ onChanged: (v) {
630
+ if (v != null) theme.value = v;
631
+ },
632
+ ),
633
+ ),
634
+ ]),
635
+ actions: [
636
+ TextButton(
637
+ onPressed: () => Navigator.pop(dialogContext, false),
638
+ child: const Text('انصراف')),
639
+ FilledButton(
640
+ onPressed: () async {
641
+ await widget.api.updateProfile(
642
+ displayName: name.text.trim(),
643
+ themePreference: theme.value);
644
+ if (dialogContext.mounted) Navigator.pop(dialogContext, true);
645
+ },
646
+ child: const Text('ذخیره'),
647
+ ),
648
+ ],
649
+ ),
650
+ );
651
+ name.dispose();
652
+ theme.dispose();
653
+ if (saved == true && mounted) setState(() => data = load());
654
+ }
655
656
Future<void> createFamily() async {
657
final name = TextEditingController();
@@ -598,18 +659,19 @@ class _ProfileFamilyPageState extends State<ProfileFamilyPage> {
659
context: context,
660
builder: (dialogContext) => AlertDialog(
661
title: const Text('ساخت فضای خانواده'),
601
- content: TextField(controller: name, decoration: const InputDecoration(labelText: 'نام خانواده')),
662
+ content: TextField(
663
+ controller: name,
664
+ decoration: const InputDecoration(labelText: 'نام خانواده')),
665
actions: [
603
- TextButton(onPressed: () => Navigator.pop(dialogContext, false), child: const Text('انصراف')),
666
+ TextButton(
667
+ onPressed: () => Navigator.pop(dialogContext, false),
668
+ child: const Text('انصراف')),
669
FilledButton(
670
onPressed: () async {
606
- if (name.text.trim().isEmpty) {
607
- return;
608
- }
609
- await widget.api.createFamily(name.text.trim(), role: 'parent_guardian');
610
- if (dialogContext.mounted) {
611
- Navigator.pop(dialogContext, true);
612
- }
671
+ if (name.text.trim().isEmpty) return;
672
+ await widget.api
673
+ .createFamily(name.text.trim(), role: 'parent_guardian');
674
+ if (dialogContext.mounted) Navigator.pop(dialogContext, true);
675
},
676
child: const Text('ساخت'),
677
),
@@ -617,9 +679,7 @@ class _ProfileFamilyPageState extends State<ProfileFamilyPage> {
679
),
680
);
681
name.dispose();
620
- if (created == true && mounted) {
621
- setState(() => data = load());
622
- }
682
+ if (created == true && mounted) setState(() => data = load());
683
}
684
685
Future<void> invite(String familyId) async {
@@ -629,58 +689,56 @@ class _ProfileFamilyPageState extends State<ProfileFamilyPage> {
689
context: context,
690
builder: (dialogContext) => AlertDialog(
691
title: const Text('دعوت فرزند / عضو'),
632
- content: Column(
633
- mainAxisSize: MainAxisSize.min,
634
- children: [
635
- TextField(
692
+ content: Column(mainAxisSize: MainAxisSize.min, children: [
693
+ TextField(
694
controller: email,
695
keyboardType: TextInputType.emailAddress,
638
- decoration: const InputDecoration(labelText: 'ایمیل'),
639
- ),
640
- const SizedBox(height: 12),
641
- ValueListenableBuilder<String>(
642
- valueListenable: choice,
643
- builder: (_, value, __) => DropdownButtonFormField<String>(
644
- initialValue: value,
645
- decoration: const InputDecoration(labelText: 'نوع عضو'),
646
- items: const [
647
- DropdownMenuItem(value: 'daughter', child: Text('فرزند دختر — سفید / صورتی')),
648
- DropdownMenuItem(value: 'son', child: Text('فرزند پسر — سفید / آبی')),
649
- DropdownMenuItem(value: 'parent', child: Text('والد / سرپرست — سفید / آبی')),
650
- DropdownMenuItem(value: 'adult', child: Text('عضو بزرگسال — سفید / آبی')),
651
- ],
652
- onChanged: (v) {
653
- if (v != null) {
654
- choice.value = v;
655
- }
656
- },
657
- ),
696
+ decoration: const InputDecoration(labelText: 'ایمیل')),
697
+ const SizedBox(height: 12),
698
+ ValueListenableBuilder<String>(
699
+ valueListenable: choice,
700
+ builder: (_, value, __) => DropdownButtonFormField<String>(
701
+ initialValue: value,
702
+ decoration: const InputDecoration(labelText: 'نوع عضو'),
703
+ items: const [
704
+ DropdownMenuItem(
705
+ value: 'daughter', child: Text('فرزند دختر — سفید / صورتی')),
706
+ DropdownMenuItem(
707
+ value: 'son', child: Text('فرزند پسر — سفید / آبی')),
708
+ DropdownMenuItem(
709
+ value: 'parent', child: Text('والد / سرپرست — سفید / آبی')),
710
+ DropdownMenuItem(
711
+ value: 'adult', child: Text('عضو بزرگسال — سفید / آبی')),
712
+ ],
713
+ onChanged: (v) {
714
+ if (v != null) choice.value = v;
715
+ },
716
),
659
- ],
660
- ),
717
+ ),
718
+ ]),
719
actions: [
720
TextButton(
663
- onPressed: () => Navigator.pop(dialogContext, false),
664
- child: const Text('انصراف'),
665
- ),
721
+ onPressed: () => Navigator.pop(dialogContext, false),
722
+ child: const Text('انصراف')),
723
FilledButton(
724
onPressed: () async {
725
final selected = choice.value;
669
- final role = switch (selected) {
670
- 'parent' => 'parent_guardian',
671
- 'adult' => 'adult_member',
672
- _ => 'teen_minor',
673
- };
674
- final theme = selected == 'daughter' ? 'girl_pink' : selected == 'son' ? 'boy_blue' : 'adult_blue';
726
+ final role = selected == 'parent'
727
+ ? 'parent_guardian'
728
+ : selected == 'adult'
729
+ ? 'adult_member'
730
+ : 'teen_minor';
731
+ final theme = selected == 'daughter'
732
+ ? 'girl_pink'
733
+ : selected == 'son'
734
+ ? 'boy_blue'
735
+ : 'adult_blue';
736
await widget.api.inviteMember(
676
- familyId: familyId,
677
- email: email.text,
678
- role: role,
679
- themePreference: theme,
680
- );
681
- if (dialogContext.mounted) {
682
- Navigator.pop(dialogContext, true);
683
- }
737
+ familyId: familyId,
738
+ email: email.text,
739
+ role: role,
740
+ themePreference: theme);
741
+ if (dialogContext.mounted) Navigator.pop(dialogContext, true);
742
},
743
child: const Text('ارسال دعوت'),
744
),
@@ -690,92 +748,98 @@ class _ProfileFamilyPageState extends State<ProfileFamilyPage> {
748
email.dispose();
749
choice.dispose();
750
if (sent == true && mounted) {
693
- ScaffoldMessenger.of(context).showSnackBar(
694
- const SnackBar(content: Text('دعوت ارسال شد.')),
695
- );
751
+ ScaffoldMessenger.of(context)
752
+ .showSnackBar(const SnackBar(content: Text('دعوت ارسال شد.')));
753
}
754
}
755
756
@override
757
Widget build(BuildContext context) => Scaffold(
701
- appBar: AppBar(title: const Text('پروفایل و خانواده')),
702
- body: FutureBuilder<List<dynamic>>(
703
- future: data,
704
- builder: (context, snapshot) {
705
- if (snapshot.hasError) {
706
- return Center(child: Text(errorText(snapshot.error!)));
707
- }
708
- if (!snapshot.hasData) {
709
- return const Center(child: CircularProgressIndicator());
710
- }
711
- final profile = snapshot.data![0] as Map<String, dynamic>;
712
- final families = snapshot.data![1] as List<Map<String, dynamic>>;
713
- return ListView(
714
- padding: const EdgeInsets.all(20),
715
- children: [
716
- Card(
717
- child: ListTile(
718
- leading: const CircleAvatar(child: Icon(Icons.person)),
719
- title: Text(profile['display_name']?.toString() ?? 'پروفایل من'),
720
- subtitle: Text(profile['email_normalized']?.toString() ?? ''),
721
- trailing: IconButton(
722
- onPressed: () => editProfile(profile),
723
- icon: const Icon(Icons.edit_outlined),
724
- ),
725
- ),
726
- ),
727
- const SizedBox(height: 12),
728
- if (families.isEmpty)
729
- Card(
730
- child: ListTile(
731
- leading: const Icon(Icons.family_restroom),
732
- title: const Text('هنوز فضای خانواده ساخته نشده'),
733
- trailing: IconButton(onPressed: createFamily, icon: const Icon(Icons.add)),
734
- ),
735
- )
736
- else
737
- ...families.map(
738
- (family) => Card(
758
+ appBar: AppBar(title: const Text('پروفایل و خانواده')),
759
+ body: FutureBuilder<List<dynamic>>(
760
+ future: data,
761
+ builder: (context, snapshot) {
762
+ if (snapshot.hasError) {
763
+ return Center(child: Text(errorText(snapshot.error!)));
764
+ }
765
+ if (!snapshot.hasData) {
766
+ return const Center(child: CircularProgressIndicator());
767
+ }
768
+ final profile = snapshot.data![0] as Map<String, dynamic>;
769
+ final families = snapshot.data![1] as List<Map<String, dynamic>>;
770
+ return ListView(
771
+ padding: const EdgeInsets.all(20),
772
+ children: [
773
+ Card(
774
child: ListTile(
740
- leading: const Icon(Icons.family_restroom),
741
- title: Text(family['name']?.toString() ?? 'خانواده'),
742
- subtitle: Text((family['is_admin'] == true ? 'مدیر خانواده · ' : '') + (family['role']?.toString() ?? '')),
743
- onTap: () => Navigator.of(context).push(
744
- MaterialPageRoute(
745
- builder: (_) => FamilyMembersPage(
746
- api: widget.api,
747
- familyId: family['id'].toString(),
748
- familyName: family['name']?.toString() ?? 'خانواده',
749
- isAdmin: family['is_admin'] == true,
750
- ),
751
- ),
752
- ),
775
+ leading: const CircleAvatar(child: Icon(Icons.person)),
776
+ title: Text(
777
+ profile['display_name']?.toString() ?? 'پروفایل من'),
778
+ subtitle:
779
+ Text(profile['email_normalized']?.toString() ?? ''),
780
trailing: IconButton(
754
- onPressed: () => invite(family['id'].toString()),
755
- icon: const Icon(Icons.person_add_alt),
756
- ),
781
+ onPressed: () => editProfile(profile),
782
+ icon: const Icon(Icons.edit_outlined)),
783
),
784
),
759
- ),
760
- ListTile(
761
- leading: const Icon(Icons.password),
762
- title: const Text('تغییر رمز عبور'),
763
- onTap: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => ChangePasswordPage(api: widget.api))),
764
- ),
765
- const ListTile(
766
- leading: Icon(Icons.privacy_tip_outlined),
767
- title: Text('حریم خصوصی و دسترسیها'),
768
- subtitle: Text('خصوصی، اعضای منتخب، والد/سرپرست، خانواده، ایمنی'),
769
- ),
770
- ],
771
- );
772
- },
773
- ),
774
- floatingActionButton: FloatingActionButton.extended(onPressed: createFamily, icon: const Icon(Icons.add), label: const Text('خانواده')),
775
- );
785
+ const SizedBox(height: 12),
786
+ if (families.isEmpty)
787
+ Card(
788
+ child: ListTile(
789
+ leading: const Icon(Icons.family_restroom),
790
+ title: const Text('هنوز فضای خانواده ساخته نشده'),
791
+ trailing: IconButton(
792
+ onPressed: createFamily,
793
+ icon: const Icon(Icons.add)),
794
+ ),
795
+ )
796
+ else
797
+ ...families.map((family) => Card(
798
+ child: ListTile(
799
+ leading: const Icon(Icons.family_restroom),
800
+ title:
801
+ Text(family['name']?.toString() ?? 'خانواده'),
802
+ subtitle: Text(
803
+ '${family['is_admin'] == true ? 'مدیر خانواده · ' : ''}${family['role'] ?? ''}'),
804
+ onTap: () => Navigator.of(context).push(
805
+ MaterialPageRoute(
806
+ builder: (_) => FamilyMembersPage(
807
+ api: widget.api,
808
+ familyId: family['id'].toString(),
809
+ familyName:
810
+ family['name']?.toString() ?? 'خانواده',
811
+ isAdmin: family['is_admin'] == true,
812
+ ),
813
+ ),
814
+ ),
815
+ trailing: IconButton(
816
+ onPressed: () => invite(family['id'].toString()),
817
+ icon: const Icon(Icons.person_add_alt)),
818
+ ),
819
+ )),
820
+ ListTile(
821
+ leading: const Icon(Icons.password),
822
+ title: const Text('تغییر رمز عبور'),
823
+ onTap: () => Navigator.of(context).push(MaterialPageRoute(
824
+ builder: (_) => ChangePasswordPage(api: widget.api))),
825
+ ),
826
+ const ListTile(
827
+ leading: Icon(Icons.privacy_tip_outlined),
828
+ title: Text('حریم خصوصی و دسترسیها'),
829
+ subtitle:
830
+ Text('خصوصی، اعضای منتخب، والد/سرپرست، خانواده، ایمنی'),
831
+ ),
832
+ ],
833
+ );
834
+ },
835
+ ),
836
+ floatingActionButton: FloatingActionButton.extended(
837
+ onPressed: createFamily,
838
+ icon: const Icon(Icons.add),
839
+ label: const Text('خانواده')),
840
+ );
841
}
842
778
-
843
class FamilyMembersPage extends StatefulWidget {
844
const FamilyMembersPage({
845
super.key,
@@ -784,19 +848,16 @@ class FamilyMembersPage extends StatefulWidget {
848
required this.familyName,
849
required this.isAdmin,
850
});
787
-
851
final IdentityApi api;
852
final String familyId;
853
final String familyName;
854
final bool isAdmin;
792
-
855
@override
856
State<FamilyMembersPage> createState() => _FamilyMembersPageState();
857
}
858
859
class _FamilyMembersPageState extends State<FamilyMembersPage> {
860
late Future<List<Map<String, dynamic>>> members;
799
-
861
@override
862
void initState() {
863
super.initState();
@@ -811,101 +872,76 @@ class _FamilyMembersPageState extends State<FamilyMembersPage> {
872
};
873
874
Future<void> configureGuardian(List<Map<String, dynamic>> items) async {
814
- final guardians = items
815
- .where((member) => member['role'] == 'parent_guardian')
816
- .toList();
817
- final minors = items.where((member) => member['role'] == 'teen_minor').toList();
875
+ final guardians =
876
+ items.where((m) => m['role'] == 'parent_guardian').toList();
877
+ final minors = items.where((m) => m['role'] == 'teen_minor').toList();
878
if (guardians.isEmpty || minors.isEmpty) {
819
- ScaffoldMessenger.of(context).showSnackBar(
820
- const SnackBar(
821
- content: Text('برای ثبت سرپرستی، حداقل یک والد و یک فرزند لازم است.'),
822
- ),
823
- );
879
+ ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
880
+ content: Text('برای ثبت سرپرستی، حداقل یک والد و یک فرزند لازم است.')));
881
return;
882
}
826
-
827
- final guardianId = ValueNotifier<String>(guardians.first['user_id'].toString());
883
+ final guardianId =
884
+ ValueNotifier<String>(guardians.first['user_id'].toString());
885
final minorId = ValueNotifier<String>(minors.first['user_id'].toString());
829
-
886
final saved = await showDialog<bool>(
887
context: context,
888
builder: (dialogContext) => AlertDialog(
889
title: const Text('رابطه والد و فرزند'),
834
- content: Column(
835
- mainAxisSize: MainAxisSize.min,
836
- children: [
837
- ValueListenableBuilder<String>(
838
- valueListenable: guardianId,
839
- builder: (_, value, __) => DropdownButtonFormField<String>(
840
- initialValue: value,
841
- decoration: const InputDecoration(labelText: 'والد / سرپرست'),
842
- items: guardians
843
- .map(
844
- (member) => DropdownMenuItem(
845
- value: member['user_id'].toString(),
846
- child: Text(member['display_name'].toString()),
847
- ),
848
- )
849
- .toList(),
850
- onChanged: (v) {
851
- if (v != null) {
852
- guardianId.value = v;
853
- }
854
- },
855
- ),
890
+ content: Column(mainAxisSize: MainAxisSize.min, children: [
891
+ ValueListenableBuilder<String>(
892
+ valueListenable: guardianId,
893
+ builder: (_, value, __) => DropdownButtonFormField<String>(
894
+ initialValue: value,
895
+ decoration: const InputDecoration(labelText: 'والد / سرپرست'),
896
+ items: guardians
897
+ .map((m) => DropdownMenuItem(
898
+ value: m['user_id'].toString(),
899
+ child: Text(m['display_name']?.toString() ?? 'والد')))
900
+ .toList(),
901
+ onChanged: (v) {
902
+ if (v != null) guardianId.value = v;
903
+ },
904
),
857
- const SizedBox(height: 12),
858
- ValueListenableBuilder<String>(
859
- valueListenable: minorId,
860
- builder: (_, value, __) => DropdownButtonFormField<String>(
861
- initialValue: value,
862
- decoration: const InputDecoration(labelText: 'فرزند'),
863
- items: minors
864
- .map(
865
- (member) => DropdownMenuItem(
866
- value: member['user_id'].toString(),
867
- child: Text(member['display_name'].toString()),
868
- ),
869
- )
870
- .toList(),
871
- onChanged: (v) {
872
- if (v != null) {
873
- minorId.value = v;
874
- }
875
- },
876
- ),
905
+ ),
906
+ const SizedBox(height: 12),
907
+ ValueListenableBuilder<String>(
908
+ valueListenable: minorId,
909
+ builder: (_, value, __) => DropdownButtonFormField<String>(
910
+ initialValue: value,
911
+ decoration: const InputDecoration(labelText: 'فرزند'),
912
+ items: minors
913
+ .map((m) => DropdownMenuItem(
914
+ value: m['user_id'].toString(),
915
+ child: Text(m['display_name']?.toString() ?? 'فرزند')))
916
+ .toList(),
917
+ onChanged: (v) {
918
+ if (v != null) minorId.value = v;
919
+ },
920
),
878
- ],
879
- ),
921
+ ),
922
+ ]),
923
actions: [
924
TextButton(
882
- onPressed: () => Navigator.pop(dialogContext, false),
883
- child: const Text('انصراف'),
884
- ),
925
+ onPressed: () => Navigator.pop(dialogContext, false),
926
+ child: const Text('انصراف')),
927
FilledButton(
928
onPressed: () async {
929
await widget.api.setGuardian(
888
- familyId: widget.familyId,
889
- guardianUserId: guardianId.value,
890
- minorUserId: minorId.value,
891
- );
892
- if (dialogContext.mounted) {
893
- Navigator.pop(dialogContext, true);
894
- }
930
+ familyId: widget.familyId,
931
+ guardianUserId: guardianId.value,
932
+ minorUserId: minorId.value);
933
+ if (dialogContext.mounted) Navigator.pop(dialogContext, true);
934
},
935
child: const Text('ثبت رابطه'),
936
),
937
],
938
),
939
);
901
-
940
guardianId.dispose();
941
minorId.dispose();
904
-
942
if (saved == true && mounted) {
943
ScaffoldMessenger.of(context).showSnackBar(
907
- const SnackBar(content: Text('رابطه سرپرستی ثبت شد.')),
908
- );
944
+ const SnackBar(content: Text('رابطه سرپرستی ثبت شد.')));
945
}
946
}
947
@@ -929,10 +965,10 @@ class _FamilyMembersPageState extends State<FamilyMembersPage> {
965
Card(
966
child: ListTile(
967
leading: const CircleAvatar(child: Icon(Icons.person)),
932
- title: Text(member['display_name']?.toString() ?? 'عضو'),
933
- subtitle: Text(
934
- roleLabel(member['role']?.toString() ?? ''),
935
- ),
968
+ title:
969
+ Text(member['display_name']?.toString() ?? 'عضو'),
970
+ subtitle:
971
+ Text(roleLabel(member['role']?.toString() ?? '')),
972
trailing: member['is_admin'] == true
973
? const Chip(label: Text('مدیر'))
974
: null,