flutter-rp-example/lib/services/auth/auth_view_model.dart
Nathan SOULIER fff5617757 First commit
2025-03-24 10:12:56 +01:00

31 lines
732 B
Dart

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());
}
}