adding packages
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../auth_service.dart';
|
||||
import '../utils.dart';
|
||||
|
||||
class ChangeEmailViewModel extends ChangeNotifier {
|
||||
final AuthService _authService;
|
||||
|
||||
ChangeEmailViewModel(this._authService);
|
||||
|
||||
bool _isLoading = false;
|
||||
bool get isLoading => _isLoading;
|
||||
|
||||
String? _errorMessage;
|
||||
String? get errorMessage => _errorMessage;
|
||||
|
||||
bool _success = false;
|
||||
bool get success => _success;
|
||||
|
||||
Future<void> requestEmailChange(String newEmail) async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
_success = false;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
await _authService.requestEmailChange(newEmail);
|
||||
_success = true;
|
||||
} catch (e) {
|
||||
_errorMessage = parseErrorMessage(e);
|
||||
rethrow;
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../auth_service.dart';
|
||||
import '../utils.dart';
|
||||
|
||||
class DeleteAccountViewModel extends ChangeNotifier {
|
||||
final AuthService _authService;
|
||||
|
||||
DeleteAccountViewModel(this._authService);
|
||||
|
||||
bool _isLoading = false;
|
||||
bool get isLoading => _isLoading;
|
||||
|
||||
String? _errorMessage;
|
||||
String? get errorMessage => _errorMessage;
|
||||
|
||||
Future<void> deleteAccount() async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
await _authService.deleteAccount();
|
||||
} catch (e) {
|
||||
_errorMessage = parseErrorMessage(e);
|
||||
rethrow;
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../auth_service.dart';
|
||||
import '../utils.dart';
|
||||
|
||||
class ForgotPasswordViewModel extends ChangeNotifier {
|
||||
final AuthService _authService;
|
||||
|
||||
ForgotPasswordViewModel(this._authService);
|
||||
|
||||
bool _isLoading = false;
|
||||
bool get isLoading => _isLoading;
|
||||
|
||||
String? _errorMessage;
|
||||
String? get errorMessage => _errorMessage;
|
||||
|
||||
bool _success = false;
|
||||
bool get success => _success;
|
||||
|
||||
Future<void> resetPassword(String email) async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
_success = false;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
await _authService.resetPassword(email);
|
||||
_success = true;
|
||||
} catch (e) {
|
||||
_errorMessage = parseErrorMessage(e);
|
||||
rethrow;
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../auth_service.dart';
|
||||
import '../utils.dart';
|
||||
|
||||
class LoginViewModel extends ChangeNotifier {
|
||||
final AuthService _authService;
|
||||
|
||||
LoginViewModel(this._authService);
|
||||
|
||||
bool _isLoading = false;
|
||||
bool get isLoading => _isLoading;
|
||||
|
||||
String? _errorMessage;
|
||||
String? get errorMessage => _errorMessage;
|
||||
|
||||
Future<void> login(String email, String password) async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
await _authService.login(email, password);
|
||||
} catch (e) {
|
||||
_errorMessage = parseErrorMessage(e);
|
||||
rethrow;
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../auth_service.dart';
|
||||
import '../utils.dart';
|
||||
|
||||
class RegisterViewModel extends ChangeNotifier {
|
||||
final AuthService _authService;
|
||||
|
||||
RegisterViewModel(this._authService);
|
||||
|
||||
bool _isLoading = false;
|
||||
bool get isLoading => _isLoading;
|
||||
|
||||
String? _errorMessage;
|
||||
String? get errorMessage => _errorMessage;
|
||||
|
||||
Future<void> signup(
|
||||
String email,
|
||||
String password,
|
||||
String confirmPassword,
|
||||
) async {
|
||||
if (password != confirmPassword) {
|
||||
_errorMessage = "Passwords do not match";
|
||||
notifyListeners();
|
||||
return; // Or throw custom error
|
||||
}
|
||||
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
await _authService.signup(email, password);
|
||||
} catch (e) {
|
||||
_errorMessage = parseErrorMessage(e);
|
||||
rethrow;
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../auth_service.dart';
|
||||
import '../utils.dart';
|
||||
|
||||
class UpdateProfileViewModel extends ChangeNotifier {
|
||||
final AuthService _authService;
|
||||
|
||||
UpdateProfileViewModel(this._authService);
|
||||
|
||||
bool _isLoading = false;
|
||||
bool get isLoading => _isLoading;
|
||||
|
||||
String? _errorMessage;
|
||||
String? get errorMessage => _errorMessage;
|
||||
|
||||
bool _success = false;
|
||||
bool get success => _success;
|
||||
|
||||
Future<void> updateProfile({String? name, String? avatar}) async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
_success = false;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final body = <String, dynamic>{};
|
||||
if (name != null) body['name'] = name;
|
||||
if (avatar != null) body['avatar'] = avatar;
|
||||
|
||||
await _authService.updateProfile(body);
|
||||
_success = true;
|
||||
} catch (e) {
|
||||
_errorMessage = parseErrorMessage(e);
|
||||
rethrow;
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../auth_service.dart';
|
||||
import '../utils.dart';
|
||||
|
||||
class VerifyEmailViewModel extends ChangeNotifier {
|
||||
final AuthService _authService;
|
||||
|
||||
VerifyEmailViewModel(this._authService);
|
||||
|
||||
bool _isLoading = false;
|
||||
bool get isLoading => _isLoading;
|
||||
|
||||
String? _errorMessage;
|
||||
String? get errorMessage => _errorMessage;
|
||||
|
||||
bool _success = false;
|
||||
bool get success => _success;
|
||||
|
||||
Future<void> requestVerification() async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
_success = false;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
await _authService.requestVerification();
|
||||
_success = true;
|
||||
} catch (e) {
|
||||
_errorMessage = parseErrorMessage(e);
|
||||
rethrow;
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user