feat: add arch
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../core/utils/result.dart';
|
||||
import '../data/models/user_model.dart';
|
||||
import '../data/repositories/auth_repository.dart';
|
||||
|
||||
class AuthViewModel with ChangeNotifier {
|
||||
final AuthRepository _authRepository;
|
||||
|
||||
AuthViewModel(this._authRepository);
|
||||
|
||||
bool _isLoading = false;
|
||||
String? _errorMessage;
|
||||
UserModel? _loggedInUser;
|
||||
|
||||
bool get isLoading => _isLoading;
|
||||
String? get errorMessage => _errorMessage;
|
||||
UserModel? get loggedInUser => _loggedInUser;
|
||||
|
||||
Future<void> login(String email, String password) async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
|
||||
final result = await _authRepository.login(email, password);
|
||||
|
||||
switch (result) {
|
||||
case Ok<UserModel>():
|
||||
_loggedInUser = result.value;
|
||||
// موفقیتآمیز
|
||||
break;
|
||||
case Error<UserModel>():
|
||||
_errorMessage = result.error.toString();
|
||||
// خطا
|
||||
break;
|
||||
}
|
||||
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user