Yimaru-Mobile/lib/ui/views/home/home_viewmodel.dart

56 lines
1.6 KiB
Dart

import 'package:yimaru_app/app/app.bottomsheets.dart';
import 'package:yimaru_app/app/app.locator.dart';
import 'package:yimaru_app/models/user.dart';
import 'package:yimaru_app/services/status_checker_service.dart';
import 'package:yimaru_app/ui/common/app_strings.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
import '../../../services/authentication_service.dart';
import '../../../services/in_app_update_service.dart';
class HomeViewModel extends ReactiveViewModel {
// Dependency injection
final _statusChecker = locator<StatusCheckerService>();
final _bottomSheetService = locator<BottomSheetService>();
final _inAppUpdateService = locator<InAppUpdateService>();
final _authenticationService = locator<AuthenticationService>();
@override
List<ListenableServiceMixin> get listenableServices =>
[_authenticationService];
// Current user
User? get _user => _authenticationService.user;
User? get user => _user;
// Bottom navigation
int _currentPage = 0;
int get currentPage => _currentPage;
// Bottom navigation
void showBottomSheet() {
_bottomSheetService.showCustomSheet(
title: ksHomeBottomSheetTitle,
variant: BottomSheetType.notice,
description: ksHomeBottomSheetDescription,
);
}
void setCurrentIndex(int index) {
_currentPage = index;
rebuildUi();
}
// Remote api calls
// In-app update
Future<void> inAppUpdate() async {
if (await _statusChecker.checkConnection()) {
await _inAppUpdateService.checkForUpdate();
}
}
}