Unverified Commit 2f1e7cf6 authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

Added state management docs/sample to SwitchListTile (#32147)

* Added documentation to SwitchListTile
parent f5674d70
...@@ -11,14 +11,19 @@ import 'theme_data.dart'; ...@@ -11,14 +11,19 @@ import 'theme_data.dart';
// Examples can assume: // Examples can assume:
// void setState(VoidCallback fn) { } // void setState(VoidCallback fn) { }
// bool _lights; // bool _isSelected;
enum _SwitchListTileType { material, adaptive } enum _SwitchListTileType { material, adaptive }
/// A [ListTile] with a [Switch]. In other words, a switch with a label. /// A [ListTile] with a [Switch]. In other words, a switch with a label.
/// ///
/// The entire list tile is interactive: tapping anywhere in the tile toggles /// The entire list tile is interactive: tapping anywhere in the tile toggles
/// the switch. /// the switch. Tapping and dragging the [Switch] also triggers the [onChanged]
/// callback.
///
/// To ensure that [onChanged] correctly triggers, the state passed
/// into [value] must be properly managed. This is typically done by invoking
/// [State.setState] in [onChanged] to toggle the state value.
/// ///
/// The [value], [onChanged], [activeColor], [activeThumbImage], and /// The [value], [onChanged], [activeColor], [activeThumbImage], and
/// [inactiveThumbImage] properties of this widget are identical to the /// [inactiveThumbImage] properties of this widget are identical to the
...@@ -41,18 +46,24 @@ enum _SwitchListTileType { material, adaptive } ...@@ -41,18 +46,24 @@ enum _SwitchListTileType { material, adaptive }
/// To show the [SwitchListTile] as disabled, pass null as the [onChanged] /// To show the [SwitchListTile] as disabled, pass null as the [onChanged]
/// callback. /// callback.
/// ///
/// {@tool sample} /// {@tool sample --template=stateful_widget_scaffold}
/// ///
/// This widget shows a switch that, when toggled, changes the state of a [bool] /// This widget shows a switch that, when toggled, changes the state of a [bool]
/// member field called `_lights`. /// member field called `_lights`.
/// ///
/// ```dart /// ```dart
/// SwitchListTile( /// bool _lights = false;
/// title: const Text('Lights'), ///
/// value: _lights, /// Widget build(BuildContext context) {
/// onChanged: (bool value) { setState(() { _lights = value; }); }, /// return Center(
/// secondary: const Icon(Icons.lightbulb_outline), /// child: SwitchListTile(
/// ) /// title: const Text('Lights'),
/// value: _lights,
/// onChanged: (bool value) { setState(() { _lights = value; }); },
/// secondary: const Icon(Icons.lightbulb_outline),
/// ),
/// );
/// }
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
/// ///
...@@ -149,13 +160,13 @@ class SwitchListTile extends StatelessWidget { ...@@ -149,13 +160,13 @@ class SwitchListTile extends StatelessWidget {
/// ///
/// ```dart /// ```dart
/// SwitchListTile( /// SwitchListTile(
/// value: _lights, /// value: _isSelected,
/// onChanged: (bool newValue) { /// onChanged: (bool newValue) {
/// setState(() { /// setState(() {
/// _lights = newValue; /// _isSelected = newValue;
/// }); /// });
/// }, /// },
/// title: Text('Lights'), /// title: Text('Selection'),
/// ) /// )
/// ``` /// ```
final ValueChanged<bool> onChanged; final ValueChanged<bool> onChanged;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment