Last active
January 14, 2021 07:34
-
-
Save trongdth/c35ec916457edd98a2831e6a95af819b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:bloc/bloc.dart'; | |
import 'package:flutter_bloc_back4app/blocs/login/login_states.dart'; | |
import 'package:flutter_bloc_back4app/repositories/user_repos.dart'; | |
class LoginCubit extends Cubit<LoginState> { | |
final BaseUserRepository userRepository; | |
LoginCubit({this.userRepository}) | |
: assert(userRepository != null), | |
super(LoginInitial()); | |
Future<void> loginButtonPressed({String username, String email, String password}) async { | |
emit(LoginLoading()); | |
try { | |
final user = await userRepository.authenticate( | |
username: username, | |
email: email, | |
password: password, | |
); | |
if (user != null) { | |
emit(LoginSuccess()); | |
} else { | |
emit(LoginFailure(error: 'Login Failed')); | |
} | |
} catch (error) { | |
emit(LoginFailure(error: error.toString())); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment