feat: check for correct version
This commit is contained in:
parent
b751d93be6
commit
8e379241ee
6 changed files with 169 additions and 92 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:seshat/config/constants.dart';
|
||||
import 'package:seshat/data/repositories/auth_repository.dart';
|
||||
import 'package:seshat/utils/command.dart';
|
||||
import 'package:seshat/utils/result.dart';
|
||||
|
|
@ -7,6 +8,7 @@ class LoginViewModel extends ChangeNotifier {
|
|||
LoginViewModel({required AuthRepository authRepository})
|
||||
: _authRepository = authRepository {
|
||||
login = Command1<void, (String username, String password)>(_login);
|
||||
load = Command0(_load)..execute();
|
||||
}
|
||||
|
||||
final AuthRepository _authRepository;
|
||||
|
|
@ -18,4 +20,39 @@ class LoginViewModel extends ChangeNotifier {
|
|||
final result = await _authRepository.login(username, password);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* =================================
|
||||
* =====[ COMMAND AND LOADING ]=====
|
||||
* =================================
|
||||
*/
|
||||
|
||||
late final Command0 load;
|
||||
bool isLoaded = false;
|
||||
bool isUpToDate = false;
|
||||
|
||||
Future<Result<void>> _load() async {
|
||||
final result1 = await _loadApiVersion();
|
||||
switch (result1) {
|
||||
case Ok():
|
||||
isLoaded = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
notifyListeners();
|
||||
return result1;
|
||||
}
|
||||
|
||||
Future<Result<void>> _loadApiVersion() async {
|
||||
final result = await _authRepository.getRemoteApiVersion();
|
||||
switch (result) {
|
||||
case Ok():
|
||||
isUpToDate = result.value == apiVersion;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue