I'm trying to display a text based on the state of a bloc so I decided to use BlocListener as I think that's the main purpose of of the widget. I want to display a text when the state is AuthFailed.
BlocListener
BlocListener<AuthBloc, AuthState>(
listener: (context, state) {
if (state is AuthFailed)
return Text(
'Oops, Invalid Credentials.',
style: TextStyle(color: Colors.red),
);
},
child: Container(),
),
The problem is, the text doesnt appear when the state is AuthFailed but If I use a BlocBuilder instead, it works.
BlocBuilder
BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {
if (state is AuthFailed)
return Text(
'Oops, Invalid Credentials.',
style: TextStyle(color: Colors.red),
);
return Container(
width: 0,
height: 0,
);
},
),