LifeMate — Personal, Family & Learning Companion
test/personal-notification-settings
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 'dart:js_interop'; |
| 3 | |
| 4 | import 'package:flutter/widgets.dart'; |
| 5 | import 'package:web/web.dart' as web; |
| 6 | |
| 7 | import 'aparat_player_port.dart'; |
| 8 | |
| 9 | const AparatPlayerPort defaultAparatPlayerPort = _WebPlayerPort(); |
| 10 | |
| 11 | class _WebPlayerPort implements AparatPlayerPort { |
| 12 | const _WebPlayerPort(); |
| 13 | |
| 14 | @override |
| 15 | bool get isSupported => true; |
| 16 | |
| 17 | @override |
| 18 | Widget buildFrame(BuildContext context, |
| 19 | {required Uri uri, |
| 20 | required String title, |
| 21 | required VoidCallback onFrameReady, |
| 22 | required ValueChanged<String> onError}) => |
| 23 | _AparatFrame( |
| 24 | uri: uri, title: title, onFrameReady: onFrameReady, onError: onError); |
| 25 | } |
| 26 | |
| 27 | class _AparatFrame extends StatefulWidget { |
| 28 | const _AparatFrame( |
| 29 | {required this.uri, |
| 30 | required this.title, |
| 31 | required this.onFrameReady, |
| 32 | required this.onError}); |
| 33 | |
| 34 | final Uri uri; |
| 35 | final String title; |
| 36 | final VoidCallback onFrameReady; |
| 37 | final ValueChanged<String> onError; |
| 38 | |
| 39 | @override |
| 40 | State<_AparatFrame> createState() => _AparatFrameState(); |
| 41 | } |
| 42 | |
| 43 | class _AparatFrameState extends State<_AparatFrame> { |
| 44 | web.HTMLIFrameElement? _frame; |
| 45 | Timer? _timeout; |
| 46 | |
| 47 | @override |
| 48 | Widget build(BuildContext context) => HtmlElementView.fromTagName( |
| 49 | tagName: 'iframe', |
| 50 | onElementCreated: (element) { |
| 51 | final frame = element as web.HTMLIFrameElement; |
| 52 | _frame = frame; |
| 53 | // Set all restrictions before attachment and before assigning src. |
| 54 | frame.title = widget.title; |
| 55 | frame.referrerPolicy = 'no-referrer'; |
| 56 | frame.setAttribute('sandbox', 'allow-scripts allow-same-origin'); |
| 57 | frame.setAttribute('allow', |
| 58 | "fullscreen; autoplay 'none'; camera 'none'; microphone 'none'; geolocation 'none'; payment 'none'"); |
| 59 | frame.allowFullscreen = true; |
| 60 | frame.style |
| 61 | ..width = '100%' |
| 62 | ..height = '100%' |
| 63 | ..border = '0'; |
| 64 | frame.onload = ((web.Event event) { |
| 65 | _timeout?.cancel(); |
| 66 | if (mounted) widget.onFrameReady(); |
| 67 | }).toJS; |
| 68 | frame.onerror = ((web.Event event) { |
| 69 | _timeout?.cancel(); |
| 70 | if (mounted) widget.onError('frame_load_failed'); |
| 71 | }).toJS; |
| 72 | _timeout = Timer(const Duration(seconds: 30), () { |
| 73 | if (mounted) widget.onError('frame_load_timeout'); |
| 74 | }); |
| 75 | frame.src = widget.uri.toString(); |
| 76 | }); |
| 77 | |
| 78 | @override |
| 79 | void dispose() { |
| 80 | _timeout?.cancel(); |
| 81 | final frame = _frame; |
| 82 | if (frame != null) { |
| 83 | frame.onload = null; |
| 84 | frame.onerror = null; |
| 85 | frame.remove(); |
| 86 | } |
| 87 | super.dispose(); |
| 88 | } |
| 89 | } |