diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index b48e0b98c1..cd9840c400 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -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( +/// context: context, +/// builder: (BuildContext context) { +/// int selectedRadio = 0; +/// return AlertDialog( +/// content: StatefulBuilder( +/// builder: (BuildContext context, StateSetter setState) { +/// return Column( +/// mainAxisSize: MainAxisSize.min, +/// children: List.generate(4, (int index) { +/// return Radio( +/// value: index, +/// groupValue: selectedRadio, +/// onChanged: (int value) { +/// setState(() => selectedRadio = value); +/// }, +/// ); +/// }), +/// ); +/// }, +/// ), +/// ); +/// }, +/// ); +/// ``` +/// {@end-tool} +/// /// See also: /// /// * [Builder], the platonic stateless widget.