I have a problem with understanding one behaviour in BLoC pattern. Using flutter_bloc plugin
I made a project based on this one: https://felangel.github.io/bloc/#/flutterlogintutorial
Nothing special. I have two pages with buttons to navigate between them. So if i go to the second page and then back to login page and focus on any input field i see one extra output(' state');
Step-by-step:
- Start the app -> flutter debug console: LoginInitial
- Press 'Second Page'
- Press 'Login Page'-> flutter debug console: LoginInitial
- Focus on any input field -> flutter debug console: LoginInitial
Any ideas why is this happening on the 4th step?
Login page:
Widget build(BuildContext context) {
return BlocBuilder<LoginEvent, LoginState>(
bloc: _loginBloc,
builder: (
BuildContext context,
LoginState state,
) {
print(' $state');
if (state is LoginFailure) {
_onWidgetDidBuild(() {
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text('${state.error}'),
backgroundColor: Colors.red,
),
);
});
}
return Form(
child: Column(
children: [
TextFormField(
decoration: InputDecoration(labelText: 'username'),
controller: _usernameController,
),
TextFormField(
decoration: InputDecoration(labelText: 'password'),
controller: _passwordController,
obscureText: true,
),
RaisedButton(
onPressed:
state is! LoginLoading ? _onLoginButtonPressed : null,
child: Text('Login'),
),
Container(
child:
state is LoginLoading ? CircularProgressIndicator() : null,
),
],
),
);
},
);
}
Full project: https://github.com/ViktorKirjanov/flutter_login_issue