the loading screen is popped when response are fetched, but when no data are fetched the loading screen page continues to show. when I close it and click the submit button the second time, the loading screen does not show. I am using flutter bloc. here is my codes
the event class
class Login extends SignInEvent{
@override
// TODO: implement props
List<Object?> get props => [];
final String userName;
final String password;
final String pin;
Login(this.userName,this.password,this.pin, ) :super([userName,password,pin]);
}
the bloc
if (event is Login) {
yield Loading();
final login = await loginUser(event.userName, event.password, event.pin);
yield Loaded(login);
print(login);
}
}
the state
class Loading extends SignInState{
@override
// TODO: implement props
List<Object?> get props => [];
}
class Loaded extends SignInState{
final Map response;
Loaded(this.response):super();
@override
// TODO: implement props
List<Object?> get props => [response];
}
The Ui code. Updated the question adding the UI code
Scaffold(
backgroundColor: Colors.white,
body: BlocProvider(
create: (context) => loginBloc,
child: SingleChildScrollView(
child: BlocListener<SignInBloc, SignInState>(
listener: (context, state) {
// TODO: implement listener}
if(state is Loading){
loading.showAlertDialog(context);
}
if (state is Loaded) {
if(state.response["status"] == "err") {
Navigator.of(context, rootNavigator: true).pop();
response.openBottomSheet(context,
state.response["message"]);
}
else {
Navigator.of(context, rootNavigator: true).pop();
Navigator.push(context,
MaterialPageRoute(builder: (context) => SubProfile()),);
}
}
},
child: BlocBuilder<SignInBloc, SignInState>(
bloc: loginBloc,
builder: (context, SignInState state) {
if(state is SignInInitial){
return LoginPageWidget();
}
if (state is Loading) {
}
if (state is Loaded) {
print('Loaded');
}
return LoginPageWidget();
},
),
),
),
),
),