feat: add arch

This commit is contained in:
Yashar Panahi
2025-08-02 12:31:42 +03:30
parent 59c3091b2f
commit 64c4ebf0f8
12 changed files with 231 additions and 110 deletions
+41
View File
@@ -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();
}
}