Created
March 6, 2018 04:21
-
-
Save jonahwilliams/f906f49d82639a3aa7c9bd1db9fe5ce3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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