Add some docs to StatefulBuilder (#31291)

This commit is contained in:
xster 2019-04-26 18:10:18 -07:00 committed by GitHub
parent 81af5a76dd
commit 26d7f502a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6249,6 +6249,45 @@ typedef StatefulWidgetBuilder = Widget Function(BuildContext context, StateSette
/// A platonic widget that both has state and calls a closure to obtain its child widget.
///
/// The [StateSetter] function passed to the [builder] is used to invoke a
/// rebuild instead of a typical [State]'s [State.setState].
///
/// Since the [builder] is re-invoked when the [StateSetter] is called, any
/// variables that represents state should be kept outside the [builder] function.
///
/// {@tool sample}
///
/// This example shows using an inline StatefulBuilder that rebuilds and that
/// also has state.
///
/// ```dart
/// await showDialog<void>(
/// context: context,
/// builder: (BuildContext context) {
/// int selectedRadio = 0;
/// return AlertDialog(
/// content: StatefulBuilder(
/// builder: (BuildContext context, StateSetter setState) {
/// return Column(
/// mainAxisSize: MainAxisSize.min,
/// children: List<Widget>.generate(4, (int index) {
/// return Radio<int>(
/// value: index,
/// groupValue: selectedRadio,
/// onChanged: (int value) {
/// setState(() => selectedRadio = value);
/// },
/// );
/// }),
/// );
/// },
/// ),
/// );
/// },
/// );
/// ```
/// {@end-tool}
///
/// See also:
///
/// * [Builder], the platonic stateless widget.