Last active
December 6, 2019 15:12
-
-
Save GIfatahTH/abcdcfb849e85c79ec1990c71add1f56 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 LoginFormView extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Injector( | |
inject: [ | |
Inject(() => LoginFormModel()), | |
//get teh email stream and inject it as stream | |
Inject.stream(() => Injector.get<LoginFormModel>().email, | |
name: "emailStream"), | |
//get teh password stream and inject it as stream | |
Inject.stream(() => Injector.get<LoginFormModel>().password, | |
name: "passwordStream"), | |
], | |
//controller need to be disposed. | |
disposeModels: true, | |
builder: (context, _) { | |
final model = Injector.get<LoginFormModel>(); | |
final emailSnapshot = | |
Injector.getAsReactive<String>(context: context, name: "emailStream") | |
.snapshot; | |
final passwordSnapshot = Injector.getAsReactive<String>( | |
context: context, name: "passwordStream") | |
.snapshot; | |
return Container( | |
margin: EdgeInsets.all(20), | |
child: ListView( | |
children: <Widget>[ | |
TextField( | |
keyboardType: TextInputType.emailAddress, | |
decoration: InputDecoration( | |
hintText: "your@email.com. It should contain '@'", | |
labelText: "Email Address", | |
errorText: emailSnapshot.error, | |
), | |
onChanged: model.changeEmail, | |
), | |
TextField( | |
onChanged: model.changePassword, | |
decoration: InputDecoration( | |
hintText: "Password should be more than three characters", | |
labelText: 'Password', | |
errorText: passwordSnapshot.error), | |
), | |
Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
mainAxisAlignment: MainAxisAlignment.start, | |
children: <Widget>[ | |
RaisedButton( | |
child: Text("login"), | |
onPressed: emailSnapshot.hasData && passwordSnapshot.hasData | |
? () { | |
model.submit(); | |
} | |
: null, | |
), | |
Divider(), | |
Text("Email data from snap :"), | |
Text(emailSnapshot.hasData | |
? emailSnapshot.data | |
: emailSnapshot.error ?? ""), | |
Divider(), | |
Text("Password data from snap :"), | |
Text(passwordSnapshot.hasData | |
? passwordSnapshot.data | |
: passwordSnapshot.error ?? ""), | |
], | |
) | |
], | |
), | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment