Yimaru-Mobile/lib/ui/views/learn_course/learn_course_viewmodel.dart

57 lines
1.7 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
import 'package:yimaru_app/app/app.router.dart';
import '../../../app/app.locator.dart';
import '../../../models/learn_course.dart';
import '../../../services/learn_service.dart';
import '../../../services/status_checker_service.dart';
import '../../common/enmus.dart';
class LearnCourseViewModel extends ReactiveViewModel {
// Dependency injection
final _learnService = locator<LearnService>();
final _statusChecker = locator<StatusCheckerService>();
final _navigationService = locator<NavigationService>();
@override
List<ListenableServiceMixin> get listenableServices => [_learnService];
// Learn lessons
List<LearnCourse> get _courses => _learnService.courses;
List<LearnCourse> get courses => _courses;
// Navigation
void pop() => _navigationService.back();
Future<void> navigateToLearnModule(LearnCourse course) async =>
_navigationService.navigateToLearnModuleView(course: course);
Future<void> navigateToLearnPractice(
{required int id, required String level}) async =>
await _navigationService.navigateToLearnPracticeView(
id: id,
level: level,
label: 'Begin Level Practice',
practice: LearnPractices.course,
title: 'Lets Practice Course $level',
subtitle: 'Lets quickly review what youve learned in this level!',
);
// Remote api call
// Learn courses
Future<void> getLearnCourses(int id) async =>
await runBusyFuture(_getLearnCourses(id),
busyObject: StateObjects.learnCourses);
Future<void> _getLearnCourses(int id) async {
if (await _statusChecker.checkConnection()) {
await _learnService.getLearnCourses(id);
}
}
}