LifeMate — Personal, Family & Learning Companion
feat/weekly-planner-android
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 'runtime_config.dart'; |
| 3 | |
| 4 | class EndpointSettingsPage extends StatefulWidget { |
| 5 | const EndpointSettingsPage( |
| 6 | {super.key, required this.initialConfig, required this.onSaved}); |
| 7 | final RuntimeConfig initialConfig; |
| 8 | final Future<void> Function(RuntimeConfig) onSaved; |
| 9 | @override |
| 10 | State<EndpointSettingsPage> createState() => _EndpointSettingsState(); |
| 11 | } |
| 12 | |
| 13 | class _EndpointSettingsState extends State<EndpointSettingsPage> { |
| 14 | late final TextEditingController primary = |
| 15 | TextEditingController(text: widget.initialConfig.apiBaseUrl); |
| 16 | late final TextEditingController fallback = TextEditingController( |
| 17 | text: widget.initialConfig.apiFallbackUrls.join('\n')); |
| 18 | bool busy = false; |
| 19 | String? error; |
| 20 | void selectFallback(String selected) { |
| 21 | final alternatives = <String>[ |
| 22 | primary.text.trim(), |
| 23 | ...fallback.text.split('\n').map((line) => line.trim()) |
| 24 | ].where((url) => url.isNotEmpty && url != selected).toSet(); |
| 25 | setState(() { |
| 26 | primary.text = selected; |
| 27 | fallback.text = alternatives.join('\n'); |
| 28 | error = null; |
| 29 | }); |
| 30 | } |
| 31 | |
| 32 | Future<void> save() async { |
| 33 | setState(() { |
| 34 | busy = true; |
| 35 | error = null; |
| 36 | }); |
| 37 | try { |
| 38 | final config = RuntimeConfig( |
| 39 | apiBaseUrl: primary.text, |
| 40 | apiFallbackUrls: fallback.text |
| 41 | .split('\n') |
| 42 | .map((line) => line.trim()) |
| 43 | .where((line) => line.isNotEmpty) |
| 44 | .toList()); |
| 45 | if (!config.isConfigured) { |
| 46 | throw ArgumentError('Primary endpoint is required.'); |
| 47 | } |
| 48 | await widget.onSaved(config); |
| 49 | } on ArgumentError { |
| 50 | if (mounted) { |
| 51 | setState(() => error = |
| 52 | 'نشانی HTTPS معتبر وارد کنید؛ بدون نام کاربری، رمز یا پارامتر اضافی.'); |
| 53 | } |
| 54 | } catch (_) { |
| 55 | if (mounted) { |
| 56 | setState(() => error = 'تنظیمات ذخیره نشد. دوباره تلاش کنید.'); |
| 57 | } |
| 58 | } finally { |
| 59 | if (mounted) setState(() => busy = false); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | @override |
| 64 | void dispose() { |
| 65 | primary.dispose(); |
| 66 | fallback.dispose(); |
| 67 | super.dispose(); |
| 68 | } |
| 69 | |
| 70 | @override |
| 71 | Widget build(BuildContext context) => Scaffold( |
| 72 | appBar: AppBar(title: const Text('اتصال لایفگاید')), |
| 73 | body: SafeArea( |
| 74 | child: SingleChildScrollView( |
| 75 | padding: const EdgeInsets.all(20), |
| 76 | child: Center( |
| 77 | child: ConstrainedBox( |
| 78 | constraints: const BoxConstraints(maxWidth: 520), |
| 79 | child: Column( |
| 80 | crossAxisAlignment: CrossAxisAlignment.stretch, |
| 81 | children: [ |
| 82 | Text( |
| 83 | widget.initialConfig.isConfigured |
| 84 | ? 'تنظیم اتصال' |
| 85 | : 'راهاندازی نسخه آزمایشی', |
| 86 | style: |
| 87 | Theme.of(context).textTheme.headlineSmall), |
| 88 | const SizedBox(height: 12), |
| 89 | const Text( |
| 90 | 'این نسخه به سرور مشترک خانواده متصل میشود. نشانی کامل API را فقط مطابق راهنمای مدیر سرویس وارد کنید؛ آدرس وبسایت بهتنهایی ممکن است نشانی اتصال نباشد.'), |
| 91 | const SizedBox(height: 12), |
| 92 | if (!widget.initialConfig.isConfigured) ...[ |
| 93 | const Text( |
| 94 | 'بدون نشانی یک سرویس فعال و سازگار، ورود و همگامسازی در دسترس نیست. اگر هنوز نشانی تأییدشدهای دریافت نکردهاید، لازم نیست چیزی وارد کنید.'), |
| 95 | const SizedBox(height: 12), |
| 96 | ], |
| 97 | const Text( |
| 98 | 'این کادر فقط نشانی اتصال میخواهد؛ رمز عبور، کلید یا توکن وارد نکنید.'), |
| 99 | const SizedBox(height: 12), |
| 100 | const Text( |
| 101 | 'نشانی در همین دستگاه ذخیره میشود و در بازکردن بعدی لازم نیست دوباره آن را وارد کنید. ذخیره نشانی به معنی برقرارشدن اتصال نیست؛ اتصال هنگام ورود بررسی میشود.'), |
| 102 | if (widget.initialConfig.isConfigured) ...[ |
| 103 | const SizedBox(height: 12), |
| 104 | const Text( |
| 105 | 'تغییر سرویس شما را از حساب قبلی خارج میکند. پیش از تغییر، دادههای ارسالنشده را با سرویس قبلی همگام کنید؛ با تأیید تغییر، دادههای محلی آن حساب کنار گذاشته میشوند.'), |
| 106 | ], |
| 107 | const SizedBox(height: 16), |
| 108 | TextField( |
| 109 | controller: primary, |
| 110 | enabled: !busy, |
| 111 | onChanged: (_) => setState(() => error = null), |
| 112 | textDirection: TextDirection.ltr, |
| 113 | keyboardType: TextInputType.url, |
| 114 | autocorrect: false, |
| 115 | decoration: const InputDecoration( |
| 116 | labelText: 'نشانی اتصال API', |
| 117 | hintText: 'https://…/api')), |
| 118 | const SizedBox(height: 16), |
| 119 | TextField( |
| 120 | controller: fallback, |
| 121 | enabled: !busy, |
| 122 | textDirection: TextDirection.ltr, |
| 123 | maxLines: 4, |
| 124 | autocorrect: false, |
| 125 | decoration: const InputDecoration( |
| 126 | labelText: 'نشانیهای جایگزین (اختیاری)', |
| 127 | helperText: |
| 128 | 'هر نشانی در یک سطر؛ انتخاب سرویس جایگزین با تأیید شما انجام میشود.')), |
| 129 | for (final endpoint |
| 130 | in widget.initialConfig.apiFallbackUrls) |
| 131 | Padding( |
| 132 | padding: const EdgeInsets.only(top: 8), |
| 133 | child: OutlinedButton( |
| 134 | onPressed: busy |
| 135 | ? null |
| 136 | : () => selectFallback(endpoint), |
| 137 | child: Text(endpoint, |
| 138 | textDirection: TextDirection.ltr))), |
| 139 | if (error != null) |
| 140 | Padding( |
| 141 | padding: |
| 142 | const EdgeInsets.symmetric(vertical: 12), |
| 143 | child: Text(error!, |
| 144 | style: TextStyle( |
| 145 | color: Theme.of(context) |
| 146 | .colorScheme |
| 147 | .error))), |
| 148 | const SizedBox(height: 20), |
| 149 | FilledButton( |
| 150 | onPressed: busy || primary.text.trim().isEmpty |
| 151 | ? null |
| 152 | : save, |
| 153 | child: Text( |
| 154 | busy ? 'در حال ذخیره…' : 'ذخیره و ادامه')), |
| 155 | ])), |
| 156 | ))), |
| 157 | ); |
| 158 | } |