@@ -17,9 +17,11 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
1717
1818 final AuthRepository repository;
1919
20- AuthBloc ({required this .repository}) : super (AuthInitial ()){
20+ AuthBloc ({required this .repository}) : super (const AuthInitial ()){
2121 on < AppStarted > (_onAppStarted);
2222 on < AuthByPassword > (_onAuthByPassword);
23+ on < AuthByRegister > (_onAuthByRegister);
24+ on < Logout > (_onLoggedOut);
2325 }
2426
2527 void _onAppStarted (AuthEvent event, Emitter <AuthState > emit) async {
@@ -41,7 +43,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
4143 }
4244 }
4345
44- if (event is LoggedOut ) {
46+ if (event is Logout ) {
4547
4648 }
4749 }
@@ -85,4 +87,26 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
8587 emit (const AuthFailure ('用户名和密码不匹配' ));
8688 }
8789 }
90+
91+ FutureOr <void > _onAuthByRegister (AuthByRegister event, Emitter <AuthState > emit) async {
92+ emit (AuthLoading ());
93+ TaskResult <bool > result = await repository.register (email: event.email, code: event.code);
94+
95+ // if(result.data == null){
96+ // emit(const RegisterError('注册失败'));
97+ // }else{
98+ // if (result.data!=null&&result.data!) {
99+ // // 注册成功
100+ // emit( RegisterSuccess(event.email));
101+ // }else{
102+ // emit( RegisterError(result.msg));
103+ // }
104+ // }
105+ }
106+
107+ FutureOr <void > _onLoggedOut (Logout event, Emitter <AuthState > emit) async {
108+ SharedPreferences prefs = await SharedPreferences .getInstance ();
109+ await prefs.remove (SpKey .tokenKey);
110+ emit (const AuthInitial ());
111+ }
88112}
0 commit comments