You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/features/authentication/authentication_repo.dart';
|
|
|
|
|
|
|
|
|
|
class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
AuthenticationRepo authenticationRepo;
|
|
|
|
|
|
|
|
|
|
AuthenticationViewModel({required this.authenticationRepo});
|
|
|
|
|
|
|
|
|
|
Future<void> signUp({
|
|
|
|
|
required String phone,
|
|
|
|
|
required String password,
|
|
|
|
|
Function(dynamic)? onSuccess,
|
|
|
|
|
Function(String)? onError,
|
|
|
|
|
}) async {
|
|
|
|
|
Utils.showLoading();
|
|
|
|
|
final resultEither = await authenticationRepo.signIn(
|
|
|
|
|
phone: phone,
|
|
|
|
|
password: password,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (resultEither.isLeft()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (resultEither.isRight()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resultEither.fold(
|
|
|
|
|
(failure) {
|
|
|
|
|
Utils.hideLoading();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
if (onError != null) onError(failure.message);
|
|
|
|
|
},
|
|
|
|
|
(data) {
|
|
|
|
|
Utils.hideLoading();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
if (onSuccess != null) onSuccess(data);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|