LifeMate — Personal, Family & Learning Companion
docs/offline-data-rescue-options
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 'dart:async'; |
| 2 | import 'package:flutter/material.dart'; |
| 3 | import 'api.dart'; |
| 4 | import 'notification_delivery.dart'; |
| 5 | |
| 6 | class NotificationInboxPage extends StatefulWidget { |
| 7 | const NotificationInboxPage( |
| 8 | {super.key, required this.api, this.delivery, this.embedded = false}); |
| 9 | final IdentityApi api; |
| 10 | final bool embedded; |
| 11 | final NotificationDeliveryPort? delivery; |
| 12 | @override |
| 13 | State<NotificationInboxPage> createState() => _NotificationInboxPageState(); |
| 14 | } |
| 15 | |
| 16 | class _NotificationInboxPageState extends State<NotificationInboxPage> |
| 17 | with WidgetsBindingObserver { |
| 18 | Timer? timer; |
| 19 | List<Map<String, dynamic>> items = []; |
| 20 | Object? error; |
| 21 | DateTime? refreshedAt; |
| 22 | bool loading = false; |
| 23 | late final NotificationDeliveryPort? delivery; |
| 24 | @override |
| 25 | void initState() { |
| 26 | super.initState(); |
| 27 | delivery = widget.delivery ?? |
| 28 | (widget.api is HttpIdentityApi |
| 29 | ? PollingInAppNotificationDelivery(widget.api as HttpIdentityApi) |
| 30 | : null); |
| 31 | WidgetsBinding.instance.addObserver(this); |
| 32 | reload(); |
| 33 | timer = Timer.periodic(const Duration(seconds: 30), (_) => reload()); |
| 34 | } |
| 35 | |
| 36 | @override |
| 37 | void didChangeAppLifecycleState(AppLifecycleState state) { |
| 38 | timer?.cancel(); |
| 39 | if (state == AppLifecycleState.resumed) { |
| 40 | reload(); |
| 41 | timer = Timer.periodic(const Duration(seconds: 30), (_) => reload()); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | Future<void> reload() async { |
| 46 | if (loading) return; |
| 47 | setState(() => loading = true); |
| 48 | try { |
| 49 | if (delivery == null) { |
| 50 | throw const ApiException(503, 'notification_provider_unavailable'); |
| 51 | } |
| 52 | final next = await delivery!.fetch(); |
| 53 | if (!mounted) return; |
| 54 | setState(() { |
| 55 | items = next; |
| 56 | error = null; |
| 57 | refreshedAt = DateTime.now(); |
| 58 | }); |
| 59 | } catch (failure) { |
| 60 | if (mounted) setState(() => error = failure); |
| 61 | } finally { |
| 62 | if (mounted) setState(() => loading = false); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | @override |
| 67 | void dispose() { |
| 68 | timer?.cancel(); |
| 69 | WidgetsBinding.instance.removeObserver(this); |
| 70 | super.dispose(); |
| 71 | } |
| 72 | |
| 73 | @override |
| 74 | Widget build(BuildContext context) => Scaffold( |
| 75 | appBar: widget.embedded |
| 76 | ? null |
| 77 | : AppBar(title: const Text('یادآوریهای لایفگاید'), actions: [ |
| 78 | IconButton( |
| 79 | onPressed: loading ? null : reload, |
| 80 | icon: const Icon(Icons.refresh)) |
| 81 | ]), |
| 82 | body: ListView(padding: const EdgeInsets.all(16), children: [ |
| 83 | const Text( |
| 84 | 'این یادآوریها هنگام باز بودن برنامه تازه میشوند. اعلان پسزمینه فعال نیست.'), |
| 85 | if (loading) const LinearProgressIndicator(), |
| 86 | if (error != null) |
| 87 | const Text( |
| 88 | 'تازهسازی انجام نشد؛ موارد زیر آخرین داده دریافتشدهاند، زنده نیستند.'), |
| 89 | if (refreshedAt != null) |
| 90 | Text('آخرین دریافت: ${refreshedAt!.toLocal()}'), |
| 91 | if (!loading && items.isEmpty) const Text('یادآوری دریافت نشده است.'), |
| 92 | ...items.map((item) { |
| 93 | final payload = |
| 94 | item['payload'] is Map ? item['payload'] as Map : const {}; |
| 95 | return Card( |
| 96 | child: ListTile( |
| 97 | title: |
| 98 | Text(payload['title']?.toString() ?? 'یادآوری برنامه'), |
| 99 | subtitle: Text(item['created_at']?.toString() ?? ''))); |
| 100 | }), |
| 101 | ]), |
| 102 | ); |
| 103 | } |