Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[bloc_package] LoginForm
class LoginForm extends StatelessWidget {
final LoginBloc loginBloc;
final usernameController = TextEditingController();
final passwordController = TextEditingController();
const LoginForm({Key key, @required this.loginBloc}): super(key: key);
@override
Widget build(BuildContext context) {
return BlocBuilder<LoginState>(
bloc: loginBloc,
builder: (
BuildContext context,
LoginState loginState,
) {
if (loginState.token.isNotEmpty) {
// user is authenticated do something...
}
return Form(
child: Column(
children: [
Text(
loginState.error,
),
TextFormField(
controller: usernameController,
),
TextFormField(
controller: passwordController,
obscureText: true,
),
RaisedButton(
onPressed: loginState.isLoginButtonEnabled
? _onLoginButtonPressed
: null,
child: Text('Login'),
),
Container(
child: loginState.isLoading
? CircularProgressIndicator()
: null,
),
],
),
);
},
);
}
_onLoginButtonPressed() {
loginBloc.onLoginButtonPressed(
username: usernameController.text,
password: passwordController.text,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.