Skip to content

Instantly share code, notes, and snippets.

@jonahwilliams
Created March 6, 2018 04:21
Show Gist options
  • Save jonahwilliams/f906f49d82639a3aa7c9bd1db9fe5ce3 to your computer and use it in GitHub Desktop.
Save jonahwilliams/f906f49d82639a3aa7c9bd1db9fe5ce3 to your computer and use it in GitHub Desktop.
class ParentWidget extends StatefulWidget {
const ParentWidget({Key key}) : super(key: key);
@override
State createState() => new ParentState();
}
class ParentState extends State<ParentWidget> {
String childString;
Widget build(BuildContext context) {
return new Column(children: [
new Text(childString ?? 'blank'),
new ChildWidget(updateString: updateString),
]);
}
void updateString(String value) {
setState(() {
childString = value;
});
}
}
class ChildWidget extends StatelessWidget {
ChildWidget({this.updateString});
final void Function(String) updateString;
@override
Widget build(BuildContext context) {
return new RaisedButton(child: new Text('add text'), onTap: () {
updateString('foo');
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment