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
dart 724 lines 28.7 KB
Raw
1 import 'dart:async';
2 import 'dart:ui' show SemanticsRole;
3
4 import 'package:flutter/foundation.dart' show kIsWeb;
5 import 'package:flutter/material.dart';
6
7 import 'api.dart';
8 import 'aparat_player.dart';
9 import 'learning_sync.dart';
10 import 'learning_feedback_ui.dart';
11 import 'learning_quiz_ui.dart';
12 import 'offline_store.dart';
13 import 'plan_sync.dart';
14 import 'study_ui.dart';
15
16 const learningTracks = <String, String>{
17 'common': 'عمومی',
18 'math': 'ریاضی و فیزیک',
19 'experimental': 'علوم تجربی',
20 'humanities': 'علوم انسانی',
21 };
22 const learningBookVariants = <String, String>{
23 'standard': 'نسخه معمول',
24 'experimental': 'نسخه آزمایشی',
25 'religious_variant': 'نسخه دینی متفاوت',
26 'gifted': 'استعدادهای درخشان',
27 };
28
29 bool isLearningAuthFailure(Object error) =>
30 error is ApiException &&
31 (error.statusCode == 401 || error.statusCode == 403);
32
33 String learningError(Object error) {
34 if (isOfflineFailure(error)) return 'اتصال برقرار نیست؛ دوباره تلاش کن.';
35 if (error is ApiException) {
36 if (error.statusCode == 401 || error.statusCode == 403) {
37 return 'نشست معتبر لازم است؛ دوباره وارد حساب شو.';
38 }
39 if (error.statusCode == 409) {
40 return 'این درس یک تغییر معلق یا تعارض دارد؛ ابتدا وضعیت همگام‌سازی را بررسی کن.';
41 }
42 }
43 return 'عملیات تأیید نشد؛ داده را بررسی و دوباره تلاش کن.';
44 }
45
46 /// School is a selectable life context, never a role or permission grant.
47 class EducationLibraryPage extends StatefulWidget {
48 const EducationLibraryPage({super.key, required this.api});
49 final IdentityApi api;
50 @override
51 State<EducationLibraryPage> createState() => _EducationLibraryPageState();
52 }
53
54 class _EducationLibraryPageState extends State<EducationLibraryPage> {
55 Map<String, dynamic>? library;
56 String? error;
57 String search = '';
58 bool busy = false, offline = false;
59 HttpIdentityApi? get api =>
60 widget.api is HttpIdentityApi ? widget.api as HttpIdentityApi : null;
61
62 @override
63 void initState() {
64 super.initState();
65 load();
66 }
67
68 Future<void> load() async {
69 if (api == null || busy) return;
70 setState(() => busy = true);
71 try {
72 final value = await api!.requestJson('GET', '/v1/education/library');
73 await OfflineStore.forApi(api!).writeList('education_library', [value]);
74 if (mounted) {
75 setState(() {
76 library = value;
77 error = null;
78 offline = false;
79 });
80 }
81 } catch (e) {
82 if (isLearningAuthFailure(e) && mounted) {
83 setState(() {
84 library = null;
85 offline = false;
86 });
87 }
88 if (isOfflineFailure(e)) {
89 try {
90 final cached =
91 await OfflineStore.forApi(api!).readList('education_library');
92 if (mounted && cached.isNotEmpty) {
93 setState(() {
94 library = cached.single;
95 offline = true;
96 });
97 }
98 } catch (storageError) {
99 if (mounted) setState(() => error = learningError(storageError));
100 return;
101 }
102 }
103 if (mounted) setState(() => error = learningError(e));
104 } finally {
105 if (mounted) setState(() => busy = false);
106 }
107 }
108
109 Future<void> editEducation() async {
110 if (api == null) return;
111 final education = library?['education'];
112 final saved = await showDialog<bool>(
113 context: context,
114 builder: (_) => _EducationDialog(
115 api: api!,
116 education: education is Map
117 ? Map<String, dynamic>.from(education)
118 : null));
119 if (saved == true) await load();
120 }
121
122 @override
123 Widget build(BuildContext context) {
124 if (api == null) {
125 return const Center(
126 child: Text('کتابخانه آموزشی به حساب و API واقعی نیاز دارد.'));
127 }
128 final education = library?['education'];
129 final courses = (library?['courses'] as List? ?? [])
130 .whereType<Map>()
131 .where((course) =>
132 search.isEmpty ||
133 '${course['titleFa']} ${course['bookCode']}'.contains(search))
134 .toList();
135 return ListView(padding: const EdgeInsets.all(16), children: [
136 Card(
137 child: Padding(
138 padding: const EdgeInsets.all(16),
139 child: Column(
140 crossAxisAlignment: CrossAxisAlignment.start,
141 children: [
142 Text('مدرسه من',
143 style: Theme.of(context).textTheme.headlineSmall),
144 const SizedBox(height: 8),
145 Text(education is Map
146 ? 'پایه ${education['nationalGrade']} · ${learningTracks[education['trackCode']] ?? 'رشته تعیین نشده'} · ${education['schoolYear'] ?? ''}'
147 : 'پایه تحصیلی را انتخاب کن تا کتاب‌های خودت نمایش داده شود.'),
148 const Text(
149 'از هر درس می‌توانی شروع کنی؛ تغییر پایه، برنامه و پیشرفت قبلی را پاک نمی‌کند.'),
150 TextButton.icon(
151 onPressed: busy ? null : editEducation,
152 icon: const Icon(Icons.school_outlined),
153 label: const Text('انتخاب پایه و رشته')),
154 ]))),
155 if (busy) const LinearProgressIndicator(),
156 if (error != null)
157 ListTile(
158 leading: const Icon(Icons.info_outline),
159 title: Text(error!),
160 trailing:
161 TextButton(onPressed: load, child: const Text('تازه‌سازی'))),
162 if (offline)
163 const Text('فهرست ذخیره‌شده؛ اتصال و تازگی داده تأیید نشده است.'),
164 if (library?['fetchedAt'] != null)
165 Text('آخرین دریافت: ${library!['fetchedAt']}'),
166 TextField(
167 decoration: const InputDecoration(
168 labelText: 'جستجوی کتاب', prefixIcon: Icon(Icons.search)),
169 onChanged: (value) => setState(() => search = value.trim())),
170 TextButton.icon(
171 onPressed: () => Navigator.of(context).push(MaterialPageRoute(
172 builder: (_) => LearningFeedbackPage(api: api!))),
173 icon: const Icon(Icons.feedback_outlined),
174 label: const Text('بازخورد یا پیشنهاد آموزش')),
175 const SizedBox(height: 12),
176 if (!busy && courses.isEmpty)
177 const Padding(
178 padding: EdgeInsets.all(16),
179 child: Text('برای این انتخاب، آموزش ثبت‌شده‌ای پیدا نشد.')),
180 ...courses.map((course) => Card(
181 child: ListTile(
182 leading: const Icon(Icons.menu_book_outlined),
183 title: Text(course['titleFa']?.toString() ?? 'کتاب'),
184 subtitle: Text(
185 '${course['unitCount'] ?? 0} بخش فهرست‌شده · ${course['videoUnitCount'] ?? 0} بخش دارای ویدیو\n'
186 '${course['schoolYear'] ?? 'سال نسخه نامشخص'} · ${learningBookVariants[course['variant']] ?? 'نسخه نیازمند بررسی'}\n'
187 '${(course['unitCount'] ?? 0) == 0 ? 'آموزش این کتاب هنوز گردآوری نشده است.' : 'این شمارش، کامل‌بودن دوره یا کیفیت تدریس را تأیید نمی‌کند.'}'),
188 isThreeLine: true,
189 trailing: const Icon(Icons.chevron_left),
190 onTap: () => Navigator.of(context).push(MaterialPageRoute(
191 builder: (_) => LearningCoursePage(
192 api: api!, courseId: course['id'].toString())))))),
193 const Padding(
194 padding: EdgeInsets.symmetric(vertical: 16),
195 child: Text(
196 'منابع پژوهش فعلی از آپارات‌اند؛ تا بازبینی کامل تدریس و تطبیق با کتاب، پخش آموزشی منتشر نمی‌شود. پوشش همه کتاب‌ها و هنرستان‌ها هنوز تکمیل نشده است.')),
197 ]);
198 }
199 }
200
201 class _EducationDialog extends StatefulWidget {
202 const _EducationDialog({required this.api, this.education});
203 final HttpIdentityApi api;
204 final Map<String, dynamic>? education;
205 @override
206 State<_EducationDialog> createState() => _EducationDialogState();
207 }
208
209 class _EducationDialogState extends State<_EducationDialog> {
210 int? grade;
211 String? track;
212 late final TextEditingController year;
213 bool busy = false;
214 String? error;
215 @override
216 void initState() {
217 super.initState();
218 grade = int.tryParse('${widget.education?['nationalGrade']}');
219 track = widget.education?['trackCode']?.toString();
220 year = TextEditingController(
221 text: widget.education?['schoolYear']?.toString() ?? '1405-1406');
222 }
223
224 @override
225 void dispose() {
226 year.dispose();
227 super.dispose();
228 }
229
230 Future<void> save() async {
231 if (grade == null || (grade! >= 10 && track == null)) {
232 setState(() => error = 'پایه و رشته را انتخاب کن.');
233 return;
234 }
235 setState(() => busy = true);
236 try {
237 await widget.api.requestJson('PUT', '/v1/me/education', body: {
238 'nationalGrade': grade,
239 'trackCode': grade! < 10 ? 'common' : track,
240 'schoolYear': year.text.trim()
241 });
242 if (mounted) Navigator.pop(context, true);
243 } catch (e) {
244 if (mounted) setState(() => error = learningError(e));
245 } finally {
246 if (mounted) setState(() => busy = false);
247 }
248 }
249
250 @override
251 Widget build(BuildContext context) => AlertDialog(
252 title: const Text('پایه تحصیلی من'),
253 content: SingleChildScrollView(
254 child: Column(mainAxisSize: MainAxisSize.min, children: [
255 DropdownButtonFormField<int>(
256 key: const ValueKey('education-grade'),
257 initialValue: grade,
258 decoration: const InputDecoration(labelText: 'پایه'),
259 items: List.generate(
260 12,
261 (index) => DropdownMenuItem(
262 value: index + 1, child: Text('پایه ${index + 1}'))),
263 onChanged: busy
264 ? null
265 : (value) => setState(() {
266 grade = value;
267 if (grade! < 10) track = 'common';
268 if (grade! >= 10 && track == 'common') track = null;
269 })),
270 if ((grade ?? 0) >= 10)
271 DropdownButtonFormField<String>(
272 key: const ValueKey('education-track'),
273 initialValue: track == 'common' ? null : track,
274 decoration: const InputDecoration(labelText: 'رشته'),
275 items: learningTracks.entries
276 .where((entry) => entry.key != 'common')
277 .map((entry) => DropdownMenuItem(
278 value: entry.key, child: Text(entry.value)))
279 .toList(),
280 onChanged:
281 busy ? null : (value) => setState(() => track = value)),
282 TextField(
283 key: const ValueKey('education-year'),
284 controller: year,
285 enabled: !busy,
286 decoration: const InputDecoration(
287 labelText: 'سال تحصیلی، نمونه 1405-1406')),
288 if (error != null) Text(error!),
289 ])),
290 actions: [
291 TextButton(
292 onPressed: busy ? null : () => Navigator.pop(context),
293 child: const Text('انصراف')),
294 FilledButton(
295 onPressed: busy ? null : save, child: const Text('ذخیره'))
296 ]);
297 }
298
299 class LearningCoursePage extends StatefulWidget {
300 const LearningCoursePage(
301 {super.key, required this.api, required this.courseId});
302 final HttpIdentityApi api;
303 final String courseId;
304 @override
305 State<LearningCoursePage> createState() => _LearningCoursePageState();
306 }
307
308 class _LearningCoursePageState extends State<LearningCoursePage> {
309 late final LearningSync sync;
310 Map<String, dynamic>? course;
311 String? error;
312 String search = '';
313 bool busy = false;
314 Timer? poll;
315 @override
316 void initState() {
317 super.initState();
318 sync = LearningSync(widget.api);
319 load();
320 poll = Timer.periodic(
321 const Duration(seconds: 30), (_) => load(syncPending: true));
322 }
323
324 @override
325 void dispose() {
326 poll?.cancel();
327 super.dispose();
328 }
329
330 Future<void> load({bool syncPending = false}) async {
331 if (busy) return;
332 setState(() => busy = true);
333 try {
334 Object? syncError;
335 if (syncPending) {
336 try {
337 await sync.flush();
338 } catch (e) {
339 syncError = e;
340 }
341 }
342 final value = await sync.readCourse(widget.courseId);
343 if (mounted) {
344 setState(() {
345 course = value;
346 error = syncError == null ? null : learningError(syncError);
347 });
348 }
349 } catch (e) {
350 if (mounted) {
351 setState(() {
352 if (isLearningAuthFailure(e)) {
353 course = null;
354 }
355 error = learningError(e);
356 });
357 }
358 } finally {
359 if (mounted) setState(() => busy = false);
360 }
361 }
362
363 Future<void> openLesson(Map<String, dynamic> unit) async {
364 await Navigator.of(context).push(MaterialPageRoute(
365 builder: (_) => LearningLessonPage(
366 api: widget.api,
367 courseId: widget.courseId,
368 unitId: unit['id'].toString())));
369 if (mounted) await load();
370 }
371
372 @override
373 Widget build(BuildContext context) {
374 final units = (course?['units'] as List? ?? []).whereType<Map>().toList();
375 return Scaffold(
376 appBar: AppBar(
377 title: Text(course?['titleFa']?.toString() ?? 'درس‌ها'),
378 actions: [
379 IconButton(onPressed: load, icon: const Icon(Icons.refresh))
380 ]),
381 body: ListView(padding: const EdgeInsets.all(16), children: [
382 if (busy) const LinearProgressIndicator(),
383 if (error != null) Text(error!),
384 if (course?['offline'] == true)
385 const Text(
386 'آفلاین؛ فهرست ذخیره‌شده و پیشرفت معلق ممکن است قدیمی باشد.'),
387 Text('نسخه کتاب: ${course?['schoolYear'] ?? 'نامشخص'}'),
388 if (course != null && course!['editionVerification'] != 'verified')
389 const Text(
390 'نسخه و سال این کتاب هنوز از صفحه معتبر ناشر تأیید نشده است.'),
391 if ((course?['reviewCandidateCount'] as num? ?? 0) > 0)
392 Text(
393 '${course!['reviewCandidateCount']} منبع در انتظار بازبینی کامل؛ این منابع هنوز برای آموزش منتشر نشده‌اند.'),
394 if (course?['alignmentNotesFa'] != null)
395 Text(course!['alignmentNotesFa'].toString()),
396 const Text(
397 'می‌توانی از هر بخش شروع کنی. پیشرفت، گزارش خودت است و اثبات یادگیری نیست.'),
398 TextField(
399 decoration:
400 const InputDecoration(labelText: 'جستجوی درس یا صفحه'),
401 onChanged: (value) => setState(() => search = value.trim())),
402 if (!busy && units.isEmpty)
403 const Text('ویدیوی منطبق برای این کتاب هنوز ثبت نشده است.'),
404 ...units
405 .where(
406 (u) => search.isEmpty || '${u['titleFa']}'.contains(search))
407 .map((u) {
408 final progress = u['progress'];
409 final pending = progress is Map && progress['pending_sync'] == true;
410 return Card(
411 child: ListTile(
412 leading: Icon(
413 progress is Map && progress['status'] == 'completed'
414 ? Icons.check_circle_outline
415 : Icons.play_lesson_outlined),
416 title: Text(u['titleFa']?.toString() ?? 'درس'),
417 subtitle: Text(
418 '${(u['videos'] as List? ?? []).length} منبع منتشرشده · ${u['reviewCandidateCount'] ?? 0} نامزد بازبینی${pending ? ' · تغییر ارسال‌نشده' : ''}'),
419 trailing: const Icon(Icons.chevron_left),
420 onTap: () => openLesson(Map<String, dynamic>.from(u))));
421 }),
422 ]));
423 }
424 }
425
426 class LearningLessonPage extends StatefulWidget {
427 const LearningLessonPage(
428 {super.key,
429 required this.api,
430 required this.courseId,
431 required this.unitId});
432 final HttpIdentityApi api;
433 final String courseId, unitId;
434 @override
435 State<LearningLessonPage> createState() => _LearningLessonPageState();
436 }
437
438 class _LearningLessonPageState extends State<LearningLessonPage> {
439 late final LearningSync sync;
440 Map<String, dynamic>? course, unit;
441 String? error;
442 bool busy = false;
443 int videoIndex = 0;
444 @override
445 void initState() {
446 super.initState();
447 sync = LearningSync(widget.api);
448 load();
449 }
450
451 Future<void> load({bool syncPending = false}) async {
452 if (busy) return;
453 setState(() => busy = true);
454 try {
455 Object? syncError;
456 if (syncPending) {
457 try {
458 await sync.flush();
459 } catch (e) {
460 syncError = e;
461 }
462 }
463 final value = await sync.readCourse(widget.courseId);
464 final units = (value['units'] as List).whereType<Map>();
465 final found = units.where((u) => u['id'] == widget.unitId).firstOrNull;
466 if (found == null) {
467 throw const ApiException(404, 'learning_unit_not_found');
468 }
469 if (mounted) {
470 setState(() {
471 course = value;
472 unit = Map<String, dynamic>.from(found);
473 error = syncError == null ? null : learningError(syncError);
474 });
475 }
476 } catch (e) {
477 if (mounted) {
478 setState(() {
479 if (isLearningAuthFailure(e)) {
480 course = null;
481 unit = null;
482 }
483 error = learningError(e);
484 });
485 }
486 } finally {
487 if (mounted) setState(() => busy = false);
488 }
489 }
490
491 Future<void> progress(String status) async {
492 if (busy || unit == null) return;
493 setState(() => busy = true);
494 Object? mutationError;
495 try {
496 final old = unit!['progress'];
497 await sync.setProgress(widget.unitId, status,
498 old is Map ? int.tryParse('${old['version']}') ?? 0 : 0);
499 if (mounted) setState(() => error = null);
500 } catch (e) {
501 mutationError = e;
502 } finally {
503 if (mounted) setState(() => busy = false);
504 }
505 if (mounted &&
506 (mutationError == null || !isLearningAuthFailure(mutationError))) {
507 await load();
508 }
509 if (mounted && mutationError != null) {
510 setState(() {
511 if (isLearningAuthFailure(mutationError!)) {
512 course = null;
513 unit = null;
514 }
515 error = learningError(mutationError);
516 });
517 }
518 }
519
520 Future<void> resolve() async {
521 final accept = await showDialog<bool>(
522 context: context,
523 builder: (_) => AlertDialog(
524 title: const Text('استفاده از پیشرفت سرور؟'),
525 content: const Text(
526 'تغییر معلق در سابقه بازیابی نگه داشته می‌شود و پیشرفت فعلی سرور نمایش داده خواهد شد.'),
527 actions: [
528 TextButton(
529 onPressed: () => Navigator.pop(context, false),
530 child: const Text('انصراف')),
531 FilledButton(
532 onPressed: () => Navigator.pop(context, true),
533 child: const Text('استفاده از سرور'))
534 ]));
535 if (accept != true || !mounted) return;
536 try {
537 await sync.resolveUsingServer(widget.unitId);
538 if (mounted) await load();
539 } catch (e) {
540 if (mounted) setState(() => error = learningError(e));
541 }
542 }
543
544 Future<void> plan() async {
545 if (busy || unit == null) return;
546 final date = await showDatePicker(
547 context: context,
548 initialDate: DateTime.now(),
549 firstDate: DateTime.now().subtract(const Duration(days: 1)),
550 lastDate: DateTime.now().add(const Duration(days: 730)));
551 if (date == null || !mounted) return;
552 final minutes = await showDialog<int>(
553 context: context,
554 builder: (_) => SimpleDialog(
555 title: const Text('زمان برنامه‌ریزی‌شده'),
556 children: [15, 30, 45, 60]
557 .map((m) => SimpleDialogOption(
558 onPressed: () => Navigator.pop(context, m),
559 child: Text('$m دقیقه')))
560 .toList()));
561 if (minutes == null || !mounted) return;
562 setState(() => busy = true);
563 try {
564 final outcome = await PlanSync(widget.api).create({
565 'kind': 'study_session',
566 'title': '${course?['titleFa']} · ${unit!['titleFa']}',
567 'learningUnitId': widget.unitId,
568 'visibility': 'private',
569 'startsAt': DateTime(date.year, date.month, date.day,
570 DateTime.now().hour, DateTime.now().minute)
571 .toUtc()
572 .toIso8601String(),
573 'plannedDurationSeconds': minutes * 60,
574 });
575 if (!mounted) return;
576 ScaffoldMessenger.of(context).showSnackBar(SnackBar(
577 content: Text(outcome.queued
578 ? 'برنامه روی دستگاه ثبت شد؛ تأیید سرور هنوز دریافت نشده است.'
579 : 'برنامه در سرور ثبت و تأیید شد.')));
580 if (!outcome.queued && outcome.item != null) {
581 await Navigator.of(context).push(MaterialPageRoute(
582 builder: (_) =>
583 StudyTimerPage(api: widget.api, item: outcome.item!)));
584 }
585 } catch (e) {
586 if (mounted) setState(() => error = learningError(e));
587 } finally {
588 if (mounted) setState(() => busy = false);
589 }
590 }
591
592 @override
593 Widget build(BuildContext context) {
594 final videos = (unit?['videos'] as List? ?? []).whereType<Map>().toList();
595 final video =
596 videos.isEmpty ? null : videos[videoIndex.clamp(0, videos.length - 1)];
597 final current = unit?['progress'];
598 final pending = current is Map && current['pending_sync'] == true;
599 final conflict = current is Map && current['queueStatus'] == 'conflict';
600 final progressLines = [
601 'پیشرفت شخصی: ${current is Map ? {
602 'not_started': 'شروع نشده',
603 'in_progress': 'در حال یادگیری',
604 'completed': 'تکمیل طبق گزارش من'
605 }[current['status']] ?? 'نامشخص' : 'شروع نشده'}',
606 if (pending) 'تغییر روی دستگاه ذخیره شده؛ تأیید سرور دریافت نشده است.',
607 if (current is Map && current['updatedAt'] != null)
608 'آخرین ثبت سرور: ${current['updatedAt']}',
609 ];
610 final units = (course?['units'] as List? ?? []).whereType<Map>().toList();
611 final index = units.indexWhere((u) => u['id'] == widget.unitId);
612 void move(int to) =>
613 Navigator.of(context).pushReplacement(MaterialPageRoute(
614 builder: (_) => LearningLessonPage(
615 api: widget.api,
616 courseId: widget.courseId,
617 unitId: units[to]['id'].toString())));
618 return Scaffold(
619 appBar:
620 AppBar(title: Text(unit?['titleFa']?.toString() ?? 'آموزش درس')),
621 body: ListView(padding: const EdgeInsets.all(16), children: [
622 if (busy) const LinearProgressIndicator(),
623 if (error != null) Text(error!),
624 Text(course?['titleFa']?.toString() ?? ''),
625 if (course?['offline'] == true)
626 const Text('آفلاین؛ پخش ویدیو نیاز به اینترنت دارد.'),
627 if (video != null && video['freeAccess'] != false) ...[
628 AparatPlayer(
629 key: ValueKey(video['aparatId']),
630 videoHash: video['aparatId'].toString(),
631 title: video['titleFa']?.toString() ?? 'آموزش'),
632 Text('مدرس: ${video['creatorName'] ?? 'نام تأیید نشده'}'),
633 SelectableText(video['creatorUrl']?.toString() ?? ''),
634 Text(video['qualityNotesFa']?.toString() ??
635 'بازبینی کامل کیفیت تدریس انجام نشده است.'),
636 if (video['freeAccess'] == null)
637 const Text('رایگان‌بودن و دسترسی فعلی این منبع تأیید نشده است.'),
638 const Text(
639 'نمایش ویدیو، یادگیری یا تکمیل درس را خودکار ثبت نمی‌کند.'),
640 ] else
641 const Text(
642 'برای این بخش، ویدیوی بازبینی‌شده و منتشرشده هنوز ثبت نشده است.'),
643 if (videos.length > 1)
644 Wrap(
645 spacing: 8,
646 children: List.generate(
647 videos.length,
648 (i) => ChoiceChip(
649 label: Text('منبع ${i + 1}'),
650 selected: videoIndex == i,
651 onSelected: (_) => setState(() => videoIndex = i)))),
652 const Divider(),
653 OutlinedButton.icon(
654 onPressed: unit == null
655 ? null
656 : () => Navigator.of(context).push(MaterialPageRoute(
657 builder: (_) => LearningQuizPage(
658 api: widget.api, unitId: widget.unitId))),
659 icon: const Icon(Icons.quiz_outlined),
660 label: const Text('تمرین فهم درس و مرور')),
661 TextButton.icon(
662 onPressed: unit == null
663 ? null
664 : () => Navigator.of(context).push(MaterialPageRoute(
665 builder: (_) => LearningFeedbackPage(
666 api: widget.api, unitId: widget.unitId))),
667 icon: const Icon(Icons.feedback_outlined),
668 label: const Text('گزارش ایراد این درس')),
669 Semantics(
670 key: const ValueKey('learning-progress-announcement'),
671 container: true,
672 // Flutter disallows status + liveRegion on the same node.
673 // Web status has implicit ARIA live semantics; native uses the flag.
674 role: kIsWeb ? SemanticsRole.status : SemanticsRole.none,
675 liveRegion: !kIsWeb,
676 excludeSemantics: true,
677 textDirection: Directionality.of(context),
678 label: progressLines.join('\n'),
679 child: Column(
680 crossAxisAlignment: CrossAxisAlignment.start,
681 children: progressLines.map((line) => Text(line)).toList())),
682 if (conflict)
683 TextButton(
684 onPressed: busy ? null : resolve,
685 child: const Text('حل تعارض با پیشرفت سرور')),
686 Wrap(spacing: 8, children: [
687 TextButton(
688 onPressed: busy || pending || unit == null
689 ? null
690 : () => progress('not_started'),
691 child: const Text('شروع نشده')),
692 OutlinedButton(
693 onPressed: busy || pending || unit == null
694 ? null
695 : () => progress('in_progress'),
696 child: const Text('در حال یادگیری')),
697 FilledButton(
698 onPressed: busy || pending || unit == null
699 ? null
700 : () => progress('completed'),
701 child: const Text('طبق گزارش من تکمیل شد')),
702 ]),
703 FilledButton.tonalIcon(
704 onPressed: busy || unit == null ? null : plan,
705 icon: const Icon(Icons.event_note_outlined),
706 label: const Text('افزودن درس به برنامه و تایمر')),
707 const Text(
708 'برنامه به‌صورت خصوصی ایجاد می‌شود؛ اشتراک با خانواده از تنظیمات برنامه‌ریز انجام می‌شود.'),
709 TextButton(
710 onPressed: busy ? null : () => load(syncPending: true),
711 child: const Text('همگام‌سازی و تازه‌سازی')),
712 Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
713 TextButton(
714 onPressed: index > 0 ? () => move(index - 1) : null,
715 child: const Text('بخش قبلی')),
716 TextButton(
717 onPressed: index >= 0 && index + 1 < units.length
718 ? () => move(index + 1)
719 : null,
720 child: const Text('بخش بعدی')),
721 ]),
722 ]));
723 }
724 }