LifeMate — Personal, Family & Learning Companion
fix/personal-notification-controls
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 | |
| 3 | import 'aparat_player_native.dart' |
| 4 | if (dart.library.js_interop) 'aparat_player_web.dart' as platform; |
| 5 | import 'aparat_player_policy.dart'; |
| 6 | import 'aparat_player_port.dart'; |
| 7 | |
| 8 | export 'aparat_player_policy.dart'; |
| 9 | export 'aparat_player_port.dart'; |
| 10 | export 'aparat_player_fullscreen.dart'; |
| 11 | |
| 12 | /// Click-to-load official Aparat frame. Frame readiness never records study |
| 13 | /// progress, completion or evidence that a video was watched. |
| 14 | class AparatPlayer extends StatefulWidget { |
| 15 | const AparatPlayer({super.key, required this.videoHash, required this.title}); |
| 16 | |
| 17 | final String videoHash; |
| 18 | final String title; |
| 19 | |
| 20 | @override |
| 21 | State<AparatPlayer> createState() => _AparatPlayerState(); |
| 22 | } |
| 23 | |
| 24 | class _AparatPlayerState extends State<AparatPlayer> |
| 25 | with WidgetsBindingObserver { |
| 26 | bool _loaded = false; |
| 27 | String? _error; |
| 28 | int _attempt = 0; |
| 29 | |
| 30 | @override |
| 31 | void initState() { |
| 32 | super.initState(); |
| 33 | WidgetsBinding.instance.addObserver(this); |
| 34 | } |
| 35 | |
| 36 | @override |
| 37 | void didUpdateWidget(AparatPlayer oldWidget) { |
| 38 | super.didUpdateWidget(oldWidget); |
| 39 | if (oldWidget.videoHash != widget.videoHash) { |
| 40 | _reset(); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | void _reset() { |
| 45 | _attempt++; |
| 46 | _loaded = false; |
| 47 | _error = null; |
| 48 | } |
| 49 | |
| 50 | @override |
| 51 | void didChangeAppLifecycleState(AppLifecycleState state) { |
| 52 | if (_loaded && |
| 53 | (state == AppLifecycleState.paused || |
| 54 | state == AppLifecycleState.hidden || |
| 55 | state == AppLifecycleState.detached)) { |
| 56 | setState(_reset); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | @override |
| 61 | void dispose() { |
| 62 | WidgetsBinding.instance.removeObserver(this); |
| 63 | super.dispose(); |
| 64 | } |
| 65 | |
| 66 | @override |
| 67 | Widget build(BuildContext context) { |
| 68 | final uri = aparatEmbedUri(widget.videoHash); |
| 69 | final port = AparatPlayerPortScope.maybeOf(context) ?? |
| 70 | platform.defaultAparatPlayerPort; |
| 71 | final attempt = _attempt; |
| 72 | return Directionality( |
| 73 | textDirection: TextDirection.rtl, |
| 74 | child: Card( |
| 75 | child: Padding( |
| 76 | padding: const EdgeInsets.all(16), |
| 77 | child: SingleChildScrollView( |
| 78 | child: Column(mainAxisSize: MainAxisSize.min, children: [ |
| 79 | Text(widget.title, |
| 80 | style: Theme.of(context).textTheme.titleMedium), |
| 81 | const SizedBox(height: 8), |
| 82 | const Text( |
| 83 | 'این ویدئو از سرویس آپارات بیرون از برنامه پخش میشود. با بارگذاری، ' |
| 84 | 'نشانی اینترنتی دستگاه و اطلاعات فنی اتصال برای آپارات ' |
| 85 | 'ارسال میشود؛ حریم خصوصی، کوکیها و تبلیغات تابع این سرویس ' |
| 86 | 'است. اطلاعات حساب لایفگاید ارسال نمیشود.'), |
| 87 | const SizedBox(height: 12), |
| 88 | if (uri == null) |
| 89 | const Text('شناسهٔ ویدئو معتبر نیست؛ پخشکننده باز نشد.') |
| 90 | else if (_loaded) ...[ |
| 91 | TextButton( |
| 92 | onPressed: () => setState(_reset), |
| 93 | child: const Text('بستن پخشکننده')), |
| 94 | AspectRatio( |
| 95 | aspectRatio: 16 / 9, |
| 96 | child: KeyedSubtree( |
| 97 | key: ValueKey('${widget.videoHash}:$attempt'), |
| 98 | child: port.buildFrame(context, |
| 99 | uri: uri, |
| 100 | title: widget.title, |
| 101 | onFrameReady: () {}, onError: (_) { |
| 102 | if (!mounted || attempt != _attempt) return; |
| 103 | setState(() { |
| 104 | _loaded = false; |
| 105 | _error = 'بارگذاری آپارات انجام نشد. اتصال ' |
| 106 | 'اینترنت یا دسترسی به سرویس را بررسی کنید.'; |
| 107 | }); |
| 108 | }))), |
| 109 | ] else ...[ |
| 110 | if (_error != null) |
| 111 | Padding( |
| 112 | padding: const EdgeInsets.only(bottom: 8), |
| 113 | child: Text(_error!, |
| 114 | style: TextStyle( |
| 115 | color: Theme.of(context).colorScheme.error))), |
| 116 | FilledButton.icon( |
| 117 | onPressed: () => setState(() { |
| 118 | if (!port.isSupported) { |
| 119 | _error = 'پخش در این نسخه پشتیبانی نمیشود؛ ' |
| 120 | 'از نسخهٔ وب یا اندروید لایفگاید استفاده کنید.'; |
| 121 | return; |
| 122 | } |
| 123 | _attempt++; |
| 124 | _error = null; |
| 125 | _loaded = true; |
| 126 | }), |
| 127 | icon: const Icon(Icons.play_circle_outline), |
| 128 | label: Text(_error == null |
| 129 | ? 'بارگذاری ویدئو از آپارات' |
| 130 | : 'تلاش دوباره')), |
| 131 | ], |
| 132 | const SizedBox(height: 8), |
| 133 | const Text( |
| 134 | 'پخش خودکار فعال نیست؛ برای پخش از دکمهٔ داخل قاب استفاده ' |
| 135 | 'کنید. باز شدن قاب یا زمان ویدئو، اثبات مطالعه نیست.'), |
| 136 | ]))))); |
| 137 | } |
| 138 | } |