Created
January 8, 2019 01:03
-
-
Save KickedDroid/55d8ed73b035313a458f266cef626c04 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
// Create our App, which will provide the `UserModel` to | |
// all children that require it! | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
// First, create a `ScopedModel` widget. This will provide | |
// the `model` to the children that request it. | |
return new ScopedModel<UserModel>( | |
model: new UserModel(), | |
child: new Column(children: [ | |
// Create a ScopedModelDescendant. This widget will get the | |
// UserModel from the nearest ScopedModel<UserModel>. | |
// It will hand that model to our builder method, and rebuild | |
// any time the UserModel changes (i.e. after we | |
// `notifyListeners` in the Model). | |
new ScopedModelDescendant<UserModel>( | |
// This text widget will display the value of userName and update when the value changes | |
builder: (context, child, model) => new Text('${model.userName}'), | |
), | |
]) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment