-
-
Save boeledi/561ab1d0c5a5733b3a3003953685f7cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RegistrationForm extends StatefulWidget { | |
@override | |
_RegistrationFormState createState() => _RegistrationFormState(); | |
} | |
class _RegistrationFormState extends State<RegistrationForm> { | |
late RegistrationFormBloc _registrationFormBloc; | |
@override | |
void initState() { | |
super.initState(); | |
_registrationFormBloc = RegistrationFormBloc(); | |
} | |
@override | |
void dispose() { | |
_registrationFormBloc.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Form( | |
child: Column( | |
children: <Widget>[ | |
StreamBuilder<String>( | |
stream: _registrationFormBloc.email, | |
builder: (BuildContext context, AsyncSnapshot<String> snapshot) { | |
return TextField( | |
decoration: InputDecoration( | |
labelText: 'email', | |
errorText: snapshot.error, | |
), | |
onChanged: _registrationFormBloc.onEmailChanged, | |
keyboardType: TextInputType.emailAddress, | |
); | |
}), | |
StreamBuilder<String>( | |
stream: _registrationFormBloc.password, | |
builder: (BuildContext context, AsyncSnapshot<String> snapshot) { | |
return TextField( | |
decoration: InputDecoration( | |
labelText: 'password', | |
errorText: snapshot.error, | |
), | |
obscureText: false, | |
onChanged: _registrationFormBloc.onPasswordChanged, | |
); | |
}), | |
StreamBuilder<String>( | |
stream: _registrationFormBloc.confirmPassword, | |
builder: (BuildContext context, AsyncSnapshot<String> snapshot) { | |
return TextField( | |
decoration: InputDecoration( | |
labelText: 'retype password', | |
errorText: snapshot.error, | |
), | |
obscureText: false, | |
onChanged: _registrationFormBloc.onRetypePasswordChanged, | |
); | |
}), | |
StreamBuilder<bool>( | |
stream: _registrationFormBloc.registerValid, | |
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) { | |
return RaisedButton( | |
child: Text('Register'), | |
onPressed: (snapshot.hasData && snapshot.data == true) | |
? () { | |
// launch the registration process | |
} | |
: null, | |
); | |
}), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment