Home > database >  Flutter Bloc Login
Flutter Bloc Login

Time:01-14

I have a small obstacle when logging in using dart language (flutter), I login by requesting username and password to API but the wrong username / password can still login. That's why?

Sorry I tried to post source code but always error post quest, therefore I send via screenshots.

Source Code Login Page : SS Login Page

And Source Code Login Bloc : SS Login Bloc

CodePudding user response:

Because you navigating user after login request. You are adding event (LoginSubmit) to BLoC, and then, without operation check, navigate to Dashboard. You need to check auth, and if auth is success, navigate to next screen.

CodePudding user response:

In your login page, the below line needs to move to a place where you handle state changes

Navigator.push(context, MaterialPageRoute(builder: (context) => Dashboard()))

There should be a place where you have a listener or some kind of stream builder that handles the state change. So you should have something like,

...
builder: (BuildContext context, LoginState state){
    ...
    if(state is LoginSuccess){
       Navigator.push(context, MaterialPageRoute(builder: (context) => Dashboard()));
    }
    else if(state is LoginFailed){
       // Show a snackbar with the reason for the failure. 
       // You could use scaffold or an external library depending on your preference
    }
    ...
}
...
  •  Tags:  
  • Related