簡體   English   中英

Flutter Bloc登錄狀態始終顯示失敗

[英]Flutter Bloc Login State always show failure

我正在用flutter_bloc編寫登錄應用程序,我遇到了一些問題!

  1. 登錄后,即使我有來自客戶端的響應密鑰 ,也顯示在共享的“首選項”中,登錄仍然失敗。除加載外,它始終失敗。 這是日志:

     I/flutter (23617): Key From Api Provider:f6c3e63f1a95b0709d2b70075d0d592e0c4a5f85 I/flutter (23617): f6c3e63f1a95b0709d2b70075d0d592e0c4a5f85 --> i have already saved key in SharedPrefrences I/flutter (23617): Transition { currentState: LoginState { I/flutter (23617): isUsernameValid: true, I/flutter (23617): isPasswordValid: true, I/flutter (23617): isSubmitting: true, I/flutter (23617): isSuccess: false, I/flutter (23617): isFailure: false, I/flutter (23617): }, event: LoginWithCredentialsPressed { username: yelinaung, password: asdfghjkl12345 }, nextState: LoginState { I/flutter (23617): isUsernameValid: true, I/flutter (23617): isPasswordValid: true, I/flutter (23617): isSubmitting: false, I/flutter (23617): isSuccess: false,<----- I/flutter (23617): isFailure: true, I/flutter (23617): } }``` 2.I want to Navigate to home when login return key..,I think the problem is here in login_bloc ` @override Stream<LoginState> mapEventToState( LoginEvent event, ) async* { if (event is LoginWithUserNamePass) { yield* _mapLoginWithUserNamePass( username: event.username, password: event.password); } } Stream<LoginState> _mapLoginWithUserNamePass( {String username, String password}) async* { yield LoginState.loading();----> try { ##### final String key = await _apiLoader.doLogin(username, password);##### problem here? ##### _authenticationBloc.dispatch(LoggedInNow(key));####### problem here? yield LoginState.success(); } catch (_) { yield LoginState.failure(); } } }` 

如果我刪除上面的yield LoginState.success()它將返回state-success true。
3 如果我退出應用程序並重新輸入它,它將顯示Authenticated ...如下

  I/flutter (23617): Authenticated { key: f6c3e63f1a95b0709d2b70075d0d592e0c4a5f85 }
  I/flutter (23617): LoggedIn```
and navigate to home screen ...
>Can someone solve this problem,thank .





解決了..我換了

          final String  key = await _apiLoader.doLogin(username, password);

          _authenticationBloc.dispatch(LoggedInNow(key));####### problem 
    here?
            yield LoginState.success();

        }```
TO====>

   ```try {
          await _apiLoader.doLogin(username, password);


            yield LoginState.success();

        }

另一個問題是_apiLoader.dologin is not Future<void> or it return value im idiot;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM