You've already forked flutter-rp-example
First commit
This commit is contained in:
30
lib/services/auth/auth_view_model.dart
Normal file
30
lib/services/auth/auth_view_model.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:sampleapp/services/auth/auth.dart';
|
||||
|
||||
class AuthViewModel extends ChangeNotifier {
|
||||
final AuthService authService;
|
||||
bool loggingIn = false;
|
||||
bool loggingOut = false;
|
||||
|
||||
AuthViewModel(this.authService);
|
||||
|
||||
Future<bool> login() {
|
||||
return Future.delayed(Duration.zero, () async {
|
||||
loggingIn = true;
|
||||
notifyListeners();
|
||||
await authService.login();
|
||||
loggingIn = false;
|
||||
notifyListeners();
|
||||
return authService.isLoggedIn();
|
||||
});
|
||||
}
|
||||
|
||||
Future<bool> logout() async {
|
||||
loggingOut = true;
|
||||
notifyListeners();
|
||||
await authService.logout();
|
||||
loggingOut = false;
|
||||
notifyListeners();
|
||||
return !(await authService.isLoggedIn());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user