@davoodmehraban89 / LifeMate / commits / afc038c
Fork 0

LifeMate — Personal, Family & Learning Companion

feat: connect Flutter auth profile and family flows

davoodmehraban89 committed Oct 5, 2026 at 07:43 UTC afc038c3d9f7f34fbbccb2d9d6eaa92de5c36f90
1 file changed +460 -81
apps/lifemate/lib/main.dart
+460 -81
@@ -1,17 +1,26 @@
1 import 'package:flutter/material.dart';
2 import 'package:flutter_localizations/flutter_localizations.dart';
3
4 -void main() => runApp(const LifeMateApp());
4 +import 'api.dart';
5
6 -enum MemberRole { teen, parent, adult }
7 -enum ProfileTheme { girlPink, boyBlue, adultBlue }
6 +void main() => runApp(LifeMateApp());
7
8 class LifeMateApp extends StatelessWidget {
10 - const LifeMateApp({super.key});
9 + LifeMateApp({super.key, IdentityApi? api}) : api = api ?? HttpIdentityApi();
10 + final IdentityApi api;
11
12 @override
13 Widget build(BuildContext context) {
14 const accent = Color(0xFF4D86E8);
15 + final uri = Uri.base;
16 + final token = uri.queryParameters['token'];
17 + Widget entry = SignInPage(api: api);
18 + if (token != null && uri.path.contains('verify-email')) {
19 + entry = VerifyEmailPage(api: api, token: token);
20 + } else if (token != null && uri.path.contains('reset-password')) {
21 + entry = ResetPasswordPage(api: api, token: token);
22 + }
23 +
24 return MaterialApp(
25 debugShowCheckedModeBanner: false,
26 locale: const Locale('fa'),
@@ -24,15 +33,39 @@ class LifeMateApp extends StatelessWidget {
33 theme: ThemeData(
34 colorScheme: ColorScheme.fromSeed(seedColor: accent, surface: Colors.white),
35 scaffoldBackgroundColor: const Color(0xFFF8FAFD),
36 + inputDecorationTheme: const InputDecorationTheme(border: OutlineInputBorder()),
37 useMaterial3: true,
38 ),
29 - home: const Directionality(textDirection: TextDirection.rtl, child: SignInPage()),
39 + home: Directionality(textDirection: TextDirection.rtl, child: entry),
40 );
41 }
42 }
43
44 +String errorText(Object error) {
45 + if (error is ApiException) {
46 + switch (error.code) {
47 + case 'invalid_credentials':
48 + return 'ایمیل یا رمز عبور صحیح نیست.';
49 + case 'email_not_verified':
50 + return 'ابتدا ایمیل حساب را تأیید کن.';
51 + case 'account_exists':
52 + return 'برای این ایمیل قبلاً حساب ساخته شده است.';
53 + case 'invalid_password':
54 + return 'رمز عبور باید حداقل ۱۰ کاراکتر باشد.';
55 + case 'invalid_current_password':
56 + return 'رمز فعلی صحیح نیست.';
57 + case 'invalid_or_expired_token':
58 + return 'لینک منقضی شده یا معتبر نیست.';
59 + case 'forbidden':
60 + return 'برای این عملیات دسترسی نداری.';
61 + }
62 + }
63 + return 'عملیات انجام نشد. دوباره تلاش کن.';
64 +}
65 +
66 class SignInPage extends StatefulWidget {
35 - const SignInPage({super.key});
67 + const SignInPage({super.key, required this.api});
68 + final IdentityApi api;
69 @override
70 State<SignInPage> createState() => _SignInPageState();
71 }
@@ -40,116 +73,462 @@ class SignInPage extends StatefulWidget {
73 class _SignInPageState extends State<SignInPage> {
74 final email = TextEditingController();
75 final password = TextEditingController();
76 + bool busy = false;
77 + String? error;
78 +
79 + @override
80 + void dispose() {
81 + email.dispose();
82 + password.dispose();
83 + super.dispose();
84 + }
85 +
86 + Future<void> submit() async {
87 + setState(() { busy = true; error = null; });
88 + try {
89 + await widget.api.login(email.text, password.text);
90 + if (!mounted) return;
91 + Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_) => HomeShell(api: widget.api)));
92 + } catch (e) {
93 + if (mounted) setState(() => error = errorText(e));
94 + } finally {
95 + if (mounted) setState(() => busy = false);
96 + }
97 + }
98
99 @override
100 Widget build(BuildContext context) => Scaffold(
46 - body: SafeArea(
47 - child: Center(
48 - child: ConstrainedBox(
49 - constraints: const BoxConstraints(maxWidth: 440),
50 - child: ListView(
51 - padding: const EdgeInsets.all(28),
52 - shrinkWrap: true,
53 - children: [
54 - const Icon(Icons.route_rounded, size: 64),
55 - const SizedBox(height: 16),
56 - const Text('LifeMate', textAlign: TextAlign.center, style: TextStyle(fontSize: 32, fontWeight: FontWeight.w700)),
57 - const Text('همراه شخصی، تحصیلی و خانوادگی', textAlign: TextAlign.center),
58 - const SizedBox(height: 32),
59 - TextField(controller: email, keyboardType: TextInputType.emailAddress, decoration: const InputDecoration(labelText: 'ایمیل', border: OutlineInputBorder())),
60 - const SizedBox(height: 12),
61 - TextField(controller: password, obscureText: true, decoration: const InputDecoration(labelText: 'رمز عبور', border: OutlineInputBorder())),
62 - const SizedBox(height: 16),
63 - FilledButton(onPressed: () => Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_) => const HomeShell())), child: const Text('ورود')),
64 - TextButton(onPressed: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => const RecoveryPage())), child: const Text('رمز عبور را فراموش کرده‌ام')),
65 - TextButton(onPressed: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => const RegistrationPage())), child: const Text('ساخت حساب جدید')),
66 - ],
67 - ),
68 - ),
101 + body: SafeArea(
102 + child: Center(
103 + child: ConstrainedBox(
104 + constraints: const BoxConstraints(maxWidth: 440),
105 + child: ListView(
106 + padding: const EdgeInsets.all(28),
107 + shrinkWrap: true,
108 + children: [
109 + const Icon(Icons.route_rounded, size: 64),
110 + const SizedBox(height: 16),
111 + const Text('LifeMate', textAlign: TextAlign.center, style: TextStyle(fontSize: 32, fontWeight: FontWeight.w700)),
112 + const Text('همراه شخصی، تحصیلی و خانوادگی', textAlign: TextAlign.center),
113 + const SizedBox(height: 32),
114 + TextField(controller: email, keyboardType: TextInputType.emailAddress, decoration: const InputDecoration(labelText: 'ایمیل')),
115 + const SizedBox(height: 12),
116 + TextField(controller: password, obscureText: true, decoration: const InputDecoration(labelText: 'رمز عبور')),
117 + if (error != null) Padding(padding: const EdgeInsets.only(top: 12), child: Text(error!, style: TextStyle(color: Theme.of(context).colorScheme.error))),
118 + const SizedBox(height: 16),
119 + FilledButton(onPressed: busy ? null : submit, child: Text(busy ? 'در حال ورود...' : 'ورود')),
120 + TextButton(onPressed: busy ? null : () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => RecoveryPage(api: widget.api))), child: const Text('رمز عبور را فراموش کرده‌ام')),
121 + TextButton(onPressed: busy ? null : () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => RegistrationPage(api: widget.api))), child: const Text('ساخت حساب جدید')),
122 + ],
123 ),
124 ),
71 - );
125 + ),
126 + ),
127 + );
128 }
129
74 -class RegistrationPage extends StatelessWidget {
75 - const RegistrationPage({super.key});
130 +class RegistrationPage extends StatefulWidget {
131 + const RegistrationPage({super.key, required this.api});
132 + final IdentityApi api;
133 @override
77 - Widget build(BuildContext context) => const _FormScaffold(title: 'ساخت حساب', fields: ['نام', 'ایمیل', 'رمز عبور', 'تکرار رمز عبور'], action: 'ثبت‌نام و ارسال ایمیل تأیید');
134 + State<RegistrationPage> createState() => _RegistrationPageState();
135 }
136
80 -class RecoveryPage extends StatelessWidget {
81 - const RecoveryPage({super.key});
137 +class _RegistrationPageState extends State<RegistrationPage> {
138 + final name = TextEditingController();
139 + final email = TextEditingController();
140 + final password = TextEditingController();
141 + final confirm = TextEditingController();
142 + bool busy = false;
143 + String? error;
144 +
145 + Future<void> submit() async {
146 + if (password.text != confirm.text) {
147 + setState(() => error = 'تکرار رمز عبور یکسان نیست.');
148 + return;
149 + }
150 + setState(() { busy = true; error = null; });
151 + try {
152 + await widget.api.register(displayName: name.text, email: email.text, password: password.text);
153 + if (!mounted) return;
154 + ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('حساب ساخته شد. ایمیل تأیید را بررسی کن.')));
155 + Navigator.pop(context);
156 + } catch (e) {
157 + if (mounted) setState(() => error = errorText(e));
158 + } finally {
159 + if (mounted) setState(() => busy = false);
160 + }
161 + }
162 +
163 @override
83 - Widget build(BuildContext context) => const _FormScaffold(title: 'بازیابی رمز عبور', fields: ['ایمیل تأییدشده'], action: 'ارسال لینک بازیابی');
164 + Widget build(BuildContext context) => SimpleFormPage(
165 + title: 'ساخت حساب',
166 + busy: busy,
167 + error: error,
168 + action: 'ثبت‌نام و ارسال ایمیل تأیید',
169 + onPressed: submit,
170 + fields: [
171 + TextField(controller: name, decoration: const InputDecoration(labelText: 'نام')),
172 + TextField(controller: email, keyboardType: TextInputType.emailAddress, decoration: const InputDecoration(labelText: 'ایمیل')),
173 + TextField(controller: password, obscureText: true, decoration: const InputDecoration(labelText: 'رمز عبور')),
174 + TextField(controller: confirm, obscureText: true, decoration: const InputDecoration(labelText: 'تکرار رمز عبور')),
175 + ],
176 + );
177 }
178
86 -class ChangePasswordPage extends StatelessWidget {
87 - const ChangePasswordPage({super.key});
179 +class RecoveryPage extends StatefulWidget {
180 + const RecoveryPage({super.key, required this.api});
181 + final IdentityApi api;
182 @override
89 - Widget build(BuildContext context) => const _FormScaffold(title: 'تغییر رمز عبور', fields: ['رمز فعلی', 'رمز جدید', 'تکرار رمز جدید'], action: 'ذخیره رمز جدید');
183 + State<RecoveryPage> createState() => _RecoveryPageState();
184 }
185
92 -class _FormScaffold extends StatelessWidget {
93 - const _FormScaffold({required this.title, required this.fields, required this.action});
186 +class _RecoveryPageState extends State<RecoveryPage> {
187 + final email = TextEditingController();
188 + bool busy = false;
189 + String? error;
190 + bool sent = false;
191 +
192 + Future<void> submit() async {
193 + setState(() { busy = true; error = null; });
194 + try {
195 + await widget.api.forgotPassword(email.text);
196 + if (mounted) setState(() => sent = true);
197 + } catch (e) {
198 + if (mounted) setState(() => error = errorText(e));
199 + } finally {
200 + if (mounted) setState(() => busy = false);
201 + }
202 + }
203 +
204 + @override
205 + Widget build(BuildContext context) => SimpleFormPage(
206 + title: 'بازیابی رمز عبور',
207 + busy: busy,
208 + error: error,
209 + action: sent ? 'لینک ارسال شد' : 'ارسال لینک بازیابی',
210 + onPressed: sent ? null : submit,
211 + fields: [
212 + TextField(controller: email, keyboardType: TextInputType.emailAddress, decoration: const InputDecoration(labelText: 'ایمیل تأییدشده')),
213 + if (sent) const Text('اگر حسابی با این ایمیل وجود داشته باشد، لینک بازیابی ارسال می‌شود.'),
214 + ],
215 + );
216 +}
217 +
218 +class VerifyEmailPage extends StatefulWidget {
219 + const VerifyEmailPage({super.key, required this.api, required this.token});
220 + final IdentityApi api;
221 + final String token;
222 + @override
223 + State<VerifyEmailPage> createState() => _VerifyEmailPageState();
224 +}
225 +
226 +class _VerifyEmailPageState extends State<VerifyEmailPage> {
227 + String message = 'در حال تأیید ایمیل...';
228 + @override
229 + void initState() { super.initState(); verify(); }
230 +
231 + Future<void> verify() async {
232 + try {
233 + await widget.api.verifyEmail(widget.token);
234 + if (mounted) setState(() => message = 'ایمیل با موفقیت تأیید شد.');
235 + } catch (e) {
236 + if (mounted) setState(() => message = errorText(e));
237 + }
238 + }
239 +
240 + @override
241 + Widget build(BuildContext context) => Scaffold(body: Center(child: Padding(padding: const EdgeInsets.all(24), child: Text(message))));
242 +}
243 +
244 +class ResetPasswordPage extends StatefulWidget {
245 + const ResetPasswordPage({super.key, required this.api, required this.token});
246 + final IdentityApi api;
247 + final String token;
248 + @override
249 + State<ResetPasswordPage> createState() => _ResetPasswordPageState();
250 +}
251 +
252 +class _ResetPasswordPageState extends State<ResetPasswordPage> {
253 + final password = TextEditingController();
254 + final confirm = TextEditingController();
255 + bool busy = false;
256 + String? error;
257 + bool done = false;
258 +
259 + Future<void> submit() async {
260 + if (password.text != confirm.text) {
261 + setState(() => error = 'تکرار رمز عبور یکسان نیست.');
262 + return;
263 + }
264 + setState(() { busy = true; error = null; });
265 + try {
266 + await widget.api.resetPassword(widget.token, password.text);
267 + if (mounted) setState(() => done = true);
268 + } catch (e) {
269 + if (mounted) setState(() => error = errorText(e));
270 + } finally {
271 + if (mounted) setState(() => busy = false);
272 + }
273 + }
274 +
275 + @override
276 + Widget build(BuildContext context) => SimpleFormPage(
277 + title: 'ساخت رمز جدید',
278 + busy: busy,
279 + error: error,
280 + action: done ? 'رمز تغییر کرد' : 'ذخیره رمز جدید',
281 + onPressed: done ? null : submit,
282 + fields: [
283 + TextField(controller: password, obscureText: true, decoration: const InputDecoration(labelText: 'رمز جدید')),
284 + TextField(controller: confirm, obscureText: true, decoration: const InputDecoration(labelText: 'تکرار رمز جدید')),
285 + ],
286 + );
287 +}
288 +
289 +class ChangePasswordPage extends StatefulWidget {
290 + const ChangePasswordPage({super.key, required this.api});
291 + final IdentityApi api;
292 + @override
293 + State<ChangePasswordPage> createState() => _ChangePasswordPageState();
294 +}
295 +
296 +class _ChangePasswordPageState extends State<ChangePasswordPage> {
297 + final current = TextEditingController();
298 + final next = TextEditingController();
299 + final confirm = TextEditingController();
300 + bool busy = false;
301 + String? error;
302 +
303 + Future<void> submit() async {
304 + if (next.text != confirm.text) {
305 + setState(() => error = 'تکرار رمز عبور یکسان نیست.');
306 + return;
307 + }
308 + setState(() { busy = true; error = null; });
309 + try {
310 + await widget.api.changePassword(current.text, next.text);
311 + if (!mounted) return;
312 + ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('رمز عبور تغییر کرد.')));
313 + Navigator.pop(context);
314 + } catch (e) {
315 + if (mounted) setState(() => error = errorText(e));
316 + } finally {
317 + if (mounted) setState(() => busy = false);
318 + }
319 + }
320 +
321 + @override
322 + Widget build(BuildContext context) => SimpleFormPage(
323 + title: 'تغییر رمز عبور',
324 + busy: busy,
325 + error: error,
326 + action: 'ذخیره رمز جدید',
327 + onPressed: submit,
328 + fields: [
329 + TextField(controller: current, obscureText: true, decoration: const InputDecoration(labelText: 'رمز فعلی')),
330 + TextField(controller: next, obscureText: true, decoration: const InputDecoration(labelText: 'رمز جدید')),
331 + TextField(controller: confirm, obscureText: true, decoration: const InputDecoration(labelText: 'تکرار رمز جدید')),
332 + ],
333 + );
334 +}
335 +
336 +class SimpleFormPage extends StatelessWidget {
337 + const SimpleFormPage({super.key, required this.title, required this.fields, required this.action, required this.onPressed, this.busy = false, this.error});
338 final String title;
95 - final List<String> fields;
339 + final List<Widget> fields;
340 final String action;
341 + final VoidCallback? onPressed;
342 + final bool busy;
343 + final String? error;
344 +
345 @override
346 Widget build(BuildContext context) => Scaffold(
99 - appBar: AppBar(title: Text(title)),
100 - body: Center(child: ConstrainedBox(constraints: const BoxConstraints(maxWidth: 520), child: ListView(padding: const EdgeInsets.all(24), children: [
101 - ...fields.map((f) => Padding(padding: const EdgeInsets.only(bottom: 12), child: TextField(obscureText: f.contains('رمز'), decoration: InputDecoration(labelText: f, border: const OutlineInputBorder())))),
102 - FilledButton(onPressed: () {}, child: Text(action)),
103 - ]))),
104 - );
347 + appBar: AppBar(title: Text(title)),
348 + body: Center(
349 + child: ConstrainedBox(
350 + constraints: const BoxConstraints(maxWidth: 520),
351 + child: ListView(
352 + padding: const EdgeInsets.all(24),
353 + children: [
354 + for (final field in fields) Padding(padding: const EdgeInsets.only(bottom: 12), child: field),
355 + if (error != null) Padding(padding: const EdgeInsets.only(bottom: 12), child: Text(error!, style: TextStyle(color: Theme.of(context).colorScheme.error))),
356 + FilledButton(onPressed: busy ? null : onPressed, child: Text(busy ? 'لطفاً صبر کن...' : action)),
357 + ],
358 + ),
359 + ),
360 + ),
361 + );
362 }
363
364 class HomeShell extends StatefulWidget {
108 - const HomeShell({super.key});
365 + const HomeShell({super.key, required this.api});
366 + final IdentityApi api;
367 @override
368 State<HomeShell> createState() => _HomeShellState();
369 }
370
371 class _HomeShellState extends State<HomeShell> {
372 int index = 0;
115 - static const destinations = ['امروز', 'برنامه', 'تقویم', 'کارها', 'امتحان‌ها', 'تمرکز', 'همراه هوشمند'];
373 + static const destinations = ['امروز', 'برنامه هفتگی', 'تقویم', 'تکالیف و کارها', 'امتحان‌ها و نمرات', 'تمرکز', 'همراه هوشمند'];
374 +
375 @override
376 Widget build(BuildContext context) => Scaffold(
118 - appBar: AppBar(title: Text(destinations[index]), actions: [IconButton(onPressed: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => const ProfileFamilyPage())), icon: const Icon(Icons.person_outline))]),
119 - body: Center(child: Text(destinations[index], style: Theme.of(context).textTheme.headlineMedium)),
120 - bottomNavigationBar: NavigationBar(
121 - selectedIndex: index > 4 ? 0 : index,
122 - onDestinationSelected: (i) => setState(() => index = i),
123 - destinations: const [
124 - NavigationDestination(icon: Icon(Icons.home_outlined), label: 'امروز'),
125 - NavigationDestination(icon: Icon(Icons.schedule_outlined), label: 'برنامه'),
126 - NavigationDestination(icon: Icon(Icons.calendar_month_outlined), label: 'تقویم'),
127 - NavigationDestination(icon: Icon(Icons.task_alt_outlined), label: 'کارها'),
128 - NavigationDestination(icon: Icon(Icons.school_outlined), label: 'امتحان‌ها'),
377 + appBar: AppBar(
378 + title: Text(destinations[index]),
379 + actions: [
380 + IconButton(
381 + onPressed: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => ProfileFamilyPage(api: widget.api))),
382 + icon: const Icon(Icons.person_outline),
383 + ),
384 + ],
385 + ),
386 + body: Center(child: Text(destinations[index], style: Theme.of(context).textTheme.headlineMedium)),
387 + bottomNavigationBar: NavigationBar(
388 + selectedIndex: index > 4 ? 0 : index,
389 + onDestinationSelected: (i) => setState(() => index = i),
390 + destinations: const [
391 + NavigationDestination(icon: Icon(Icons.home_outlined), label: 'امروز'),
392 + NavigationDestination(icon: Icon(Icons.schedule_outlined), label: 'برنامه'),
393 + NavigationDestination(icon: Icon(Icons.calendar_month_outlined), label: 'تقویم'),
394 + NavigationDestination(icon: Icon(Icons.task_alt_outlined), label: 'کارها'),
395 + NavigationDestination(icon: Icon(Icons.school_outlined), label: 'امتحان‌ها'),
396 + ],
397 + ),
398 + drawer: Drawer(
399 + child: SafeArea(
400 + child: ListView(
401 + children: [
402 + const ListTile(title: Text('LifeMate'), subtitle: Text('منوی اصلی')),
403 + ...destinations.asMap().entries.map((e) => ListTile(title: Text(e.value), onTap: () { setState(() => index = e.key); Navigator.pop(context); })),
404 + const Divider(),
405 + ListTile(
406 + leading: const Icon(Icons.family_restroom),
407 + title: const Text('خانواده'),
408 + onTap: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => ProfileFamilyPage(api: widget.api))),
409 + ),
410 ],
411 ),
131 - drawer: Drawer(child: SafeArea(child: ListView(children: [
132 - const ListTile(title: Text('LifeMate'), subtitle: Text('منو')),
133 - ...destinations.asMap().entries.map((e) => ListTile(title: Text(e.value), onTap: () { setState(() => index = e.key); Navigator.pop(context); })),
134 - const Divider(),
135 - ListTile(leading: const Icon(Icons.family_restroom), title: const Text('خانواده'), onTap: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => const ProfileFamilyPage()))),
136 - ]))),
137 - );
412 + ),
413 + ),
414 + );
415 +}
416 +
417 +class ProfileFamilyPage extends StatefulWidget {
418 + const ProfileFamilyPage({super.key, required this.api});
419 + final IdentityApi api;
420 + @override
421 + State<ProfileFamilyPage> createState() => _ProfileFamilyPageState();
422 }
423
140 -class ProfileFamilyPage extends StatelessWidget {
141 - const ProfileFamilyPage({super.key});
424 +class _ProfileFamilyPageState extends State<ProfileFamilyPage> {
425 + late Future<List<dynamic>> data;
426 + @override
427 + void initState() { super.initState(); data = load(); }
428 +
429 + Future<List<dynamic>> load() async => [await widget.api.getProfile(), await widget.api.listFamilies()];
430 +
431 + Future<void> createFamily() async {
432 + final name = TextEditingController();
433 + final created = await showDialog<bool>(
434 + context: context,
435 + builder: (dialogContext) => AlertDialog(
436 + title: const Text('ساخت فضای خانواده'),
437 + content: TextField(controller: name, decoration: const InputDecoration(labelText: 'نام خانواده')),
438 + actions: [
439 + TextButton(onPressed: () => Navigator.pop(dialogContext, false), child: const Text('انصراف')),
440 + FilledButton(
441 + onPressed: () async {
442 + if (name.text.trim().isEmpty) return;
443 + await widget.api.createFamily(name.text.trim(), role: 'parent_guardian');
444 + if (dialogContext.mounted) Navigator.pop(dialogContext, true);
445 + },
446 + child: const Text('ساخت'),
447 + ),
448 + ],
449 + ),
450 + );
451 + name.dispose();
452 + if (created == true && mounted) setState(() => data = load());
453 + }
454 +
455 + Future<void> invite(String familyId) async {
456 + final email = TextEditingController();
457 + final sent = await showDialog<bool>(
458 + context: context,
459 + builder: (dialogContext) => AlertDialog(
460 + title: const Text('دعوت فرزند / عضو'),
461 + content: TextField(controller: email, keyboardType: TextInputType.emailAddress, decoration: const InputDecoration(labelText: 'ایمیل')),
462 + actions: [
463 + TextButton(onPressed: () => Navigator.pop(dialogContext, false), child: const Text('انصراف')),
464 + FilledButton(
465 + onPressed: () async {
466 + await widget.api.inviteMember(familyId: familyId, email: email.text, role: 'teen_minor');
467 + if (dialogContext.mounted) Navigator.pop(dialogContext, true);
468 + },
469 + child: const Text('ارسال دعوت'),
470 + ),
471 + ],
472 + ),
473 + );
474 + email.dispose();
475 + if (sent == true && mounted) ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('دعوت ارسال شد.')));
476 + }
477 +
478 @override
479 Widget build(BuildContext context) => Scaffold(
144 - appBar: AppBar(title: const Text('پروفایل و خانواده')),
145 - body: ListView(padding: const EdgeInsets.all(20), children: [
146 - const Card(child: ListTile(leading: CircleAvatar(child: Icon(Icons.person)), title: Text('پروفایل من'), subtitle: Text('نقش، اطلاعات شخصی و تم'))),
147 - Card(child: Column(children: [
148 - const ListTile(leading: Icon(Icons.family_restroom), title: Text('Family Workspace'), subtitle: Text('اعضا، نقش‌ها و دسترسی‌ها')),
149 - ListTile(leading: const Icon(Icons.person_add_alt), title: const Text('دعوت عضو'), onTap: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => const _FormScaffold(title: 'دعوت به خانواده', fields: ['ایمیل', 'نقش'], action: 'ارسال دعوت')))),
150 - ])),
151 - ListTile(leading: const Icon(Icons.password), title: const Text('تغییر رمز عبور'), onTap: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => const ChangePasswordPage()))),
152 - const ListTile(leading: Icon(Icons.privacy_tip_outlined), title: Text('حریم خصوصی و دسترسی‌ها'), subtitle: Text('خصوصی، اعضای منتخب، والد/سرپرست، خانواده، ایمنی')),
153 - ]),
154 - );
480 + appBar: AppBar(title: const Text('پروفایل و خانواده')),
481 + body: FutureBuilder<List<dynamic>>(
482 + future: data,
483 + builder: (context, snapshot) {
484 + if (snapshot.hasError) return Center(child: Text(errorText(snapshot.error!)));
485 + if (!snapshot.hasData) return const Center(child: CircularProgressIndicator());
486 + final profile = snapshot.data![0] as Map<String, dynamic>;
487 + final families = snapshot.data![1] as List<Map<String, dynamic>>;
488 + return ListView(
489 + padding: const EdgeInsets.all(20),
490 + children: [
491 + Card(
492 + child: ListTile(
493 + leading: const CircleAvatar(child: Icon(Icons.person)),
494 + title: Text(profile['display_name']?.toString() ?? 'پروفایل من'),
495 + subtitle: Text(profile['email_normalized']?.toString() ?? ''),
496 + ),
497 + ),
498 + const SizedBox(height: 12),
499 + if (families.isEmpty)
500 + Card(
501 + child: ListTile(
502 + leading: const Icon(Icons.family_restroom),
503 + title: const Text('هنوز فضای خانواده ساخته نشده'),
504 + trailing: IconButton(onPressed: createFamily, icon: const Icon(Icons.add)),
505 + ),
506 + )
507 + else
508 + ...families.map(
509 + (family) => Card(
510 + child: ListTile(
511 + leading: const Icon(Icons.family_restroom),
512 + title: Text(family['name']?.toString() ?? 'خانواده'),
513 + subtitle: Text((family['is_admin'] == true ? 'مدیر خانواده · ' : '') + (family['role']?.toString() ?? '')),
514 + trailing: IconButton(onPressed: () => invite(family['id'].toString()), icon: const Icon(Icons.person_add_alt)),
515 + ),
516 + ),
517 + ),
518 + ListTile(
519 + leading: const Icon(Icons.password),
520 + title: const Text('تغییر رمز عبور'),
521 + onTap: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => ChangePasswordPage(api: widget.api))),
522 + ),
523 + const ListTile(
524 + leading: Icon(Icons.privacy_tip_outlined),
525 + title: Text('حریم خصوصی و دسترسی‌ها'),
526 + subtitle: Text('خصوصی، اعضای منتخب، والد/سرپرست، خانواده، ایمنی'),
527 + ),
528 + ],
529 + );
530 + },
531 + ),
532 + floatingActionButton: FloatingActionButton.extended(onPressed: createFamily, icon: const Icon(Icons.add), label: const Text('خانواده')),
533 + );
534 }