login method
Implementation
Future<void> login() async {
if (state.userName == null || state.password == null) {
state =
state.copyWith(errorMessage: "Username and password cannot be empty");
return;
}
state = state.copyWith(isLoading: true);
try {
final command = UserLoginCommand(
username: state.userName!, password: state.password!);
var res = await _authService.login(command);
if (res) {
state = state.copyWith(isLoading: false, isSuccess: true);
} else {
state = state.copyWith(
isLoading: false, errorMessage: "Invalid username or password");
}
} catch (e) {
state = state.copyWith(
isLoading: false, errorMessage: e.toString(), isSuccess: false);
}
}