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

[NNBD] Migrate sample code pt 2 (#72798)

parent 3cd1166a
...@@ -10,7 +10,6 @@ import 'theme.dart'; ...@@ -10,7 +10,6 @@ import 'theme.dart';
import 'theme_data.dart'; import 'theme_data.dart';
// Examples can assume: // Examples can assume:
// // @dart = 2.9
// void setState(VoidCallback fn) { } // void setState(VoidCallback fn) { }
/// A [ListTile] with a [Checkbox]. In other words, a checkbox with a label. /// A [ListTile] with a [Checkbox]. In other words, a checkbox with a label.
...@@ -40,7 +39,7 @@ import 'theme_data.dart'; ...@@ -40,7 +39,7 @@ import 'theme_data.dart';
/// To show the [CheckboxListTile] as disabled, pass null as the [onChanged] /// To show the [CheckboxListTile] as disabled, pass null as the [onChanged]
/// callback. /// callback.
/// ///
/// {@tool dartpad --template=stateful_widget_scaffold_center_no_null_safety} /// {@tool dartpad --template=stateful_widget_scaffold_center}
/// ///
/// ![CheckboxListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile.png) /// ![CheckboxListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile.png)
/// ///
...@@ -59,8 +58,8 @@ import 'theme_data.dart'; ...@@ -59,8 +58,8 @@ import 'theme_data.dart';
/// return CheckboxListTile( /// return CheckboxListTile(
/// title: const Text('Animate Slowly'), /// title: const Text('Animate Slowly'),
/// value: timeDilation != 1.0, /// value: timeDilation != 1.0,
/// onChanged: (bool value) { /// onChanged: (bool? value) {
/// setState(() { timeDilation = value ? 10.0 : 1.0; }); /// setState(() { timeDilation = value! ? 10.0 : 1.0; });
/// }, /// },
/// secondary: const Icon(Icons.hourglass_empty), /// secondary: const Icon(Icons.hourglass_empty),
/// ); /// );
...@@ -85,7 +84,7 @@ import 'theme_data.dart'; ...@@ -85,7 +84,7 @@ import 'theme_data.dart';
/// into one. Therefore, it may be necessary to create a custom radio tile /// into one. Therefore, it may be necessary to create a custom radio tile
/// widget to accommodate similar use cases. /// widget to accommodate similar use cases.
/// ///
/// {@tool sample --template=stateful_widget_scaffold_center_no_null_safety} /// {@tool sample --template=stateful_widget_scaffold_center}
/// ///
/// ![Checkbox list tile semantics sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile_semantics.png) /// ![Checkbox list tile semantics sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile_semantics.png)
/// ///
...@@ -99,10 +98,10 @@ import 'theme_data.dart'; ...@@ -99,10 +98,10 @@ import 'theme_data.dart';
/// ```dart preamble /// ```dart preamble
/// class LinkedLabelCheckbox extends StatelessWidget { /// class LinkedLabelCheckbox extends StatelessWidget {
/// const LinkedLabelCheckbox({ /// const LinkedLabelCheckbox({
/// this.label, /// required this.label,
/// this.padding, /// required this.padding,
/// this.value, /// required this.value,
/// this.onChanged, /// required this.onChanged,
/// }); /// });
/// ///
/// final String label; /// final String label;
...@@ -133,7 +132,7 @@ import 'theme_data.dart'; ...@@ -133,7 +132,7 @@ import 'theme_data.dart';
/// ), /// ),
/// Checkbox( /// Checkbox(
/// value: value, /// value: value,
/// onChanged: (bool newValue) { /// onChanged: (bool? newValue) {
/// onChanged(newValue); /// onChanged(newValue);
/// }, /// },
/// ), /// ),
...@@ -169,7 +168,7 @@ import 'theme_data.dart'; ...@@ -169,7 +168,7 @@ import 'theme_data.dart';
/// combining [Checkbox] with other widgets, such as [Text], [Padding] and /// combining [Checkbox] with other widgets, such as [Text], [Padding] and
/// [InkWell]. /// [InkWell].
/// ///
/// {@tool dartpad --template=stateful_widget_scaffold_center_no_null_safety} /// {@tool dartpad --template=stateful_widget_scaffold_center}
/// ///
/// ![Custom checkbox list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile_custom.png) /// ![Custom checkbox list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile_custom.png)
/// ///
...@@ -179,10 +178,10 @@ import 'theme_data.dart'; ...@@ -179,10 +178,10 @@ import 'theme_data.dart';
/// ```dart preamble /// ```dart preamble
/// class LabeledCheckbox extends StatelessWidget { /// class LabeledCheckbox extends StatelessWidget {
/// const LabeledCheckbox({ /// const LabeledCheckbox({
/// this.label, /// required this.label,
/// this.padding, /// required this.padding,
/// this.value, /// required this.value,
/// this.onChanged, /// required this.onChanged,
/// }); /// });
/// ///
/// final String label; /// final String label;
...@@ -203,7 +202,7 @@ import 'theme_data.dart'; ...@@ -203,7 +202,7 @@ import 'theme_data.dart';
/// Expanded(child: Text(label)), /// Expanded(child: Text(label)),
/// Checkbox( /// Checkbox(
/// value: value, /// value: value,
/// onChanged: (bool newValue) { /// onChanged: (bool? newValue) {
/// onChanged(newValue); /// onChanged(newValue);
/// }, /// },
/// ), /// ),
......
...@@ -728,7 +728,7 @@ class DropdownButtonHideUnderline extends InheritedWidget { ...@@ -728,7 +728,7 @@ class DropdownButtonHideUnderline extends InheritedWidget {
/// dropdown's value. It should also call [State.setState] to rebuild the /// dropdown's value. It should also call [State.setState] to rebuild the
/// dropdown with the new value. /// dropdown with the new value.
/// ///
/// {@tool dartpad --template=stateful_widget_scaffold_center_no_null_safety} /// {@tool dartpad --template=stateful_widget_scaffold_center}
/// ///
/// This sample shows a `DropdownButton` with a large arrow icon, /// This sample shows a `DropdownButton` with a large arrow icon,
/// purple text style, and bold purple underline, whose value is one of "One", /// purple text style, and bold purple underline, whose value is one of "One",
...@@ -753,9 +753,9 @@ class DropdownButtonHideUnderline extends InheritedWidget { ...@@ -753,9 +753,9 @@ class DropdownButtonHideUnderline extends InheritedWidget {
/// height: 2, /// height: 2,
/// color: Colors.deepPurpleAccent, /// color: Colors.deepPurpleAccent,
/// ), /// ),
/// onChanged: (String newValue) { /// onChanged: (String? newValue) {
/// setState(() { /// setState(() {
/// dropdownValue = newValue; /// dropdownValue = newValue!;
/// }); /// });
/// }, /// },
/// items: <String>['One', 'Two', 'Free', 'Four'] /// items: <String>['One', 'Two', 'Free', 'Four']
...@@ -912,7 +912,7 @@ class DropdownButton<T> extends StatefulWidget { ...@@ -912,7 +912,7 @@ class DropdownButton<T> extends StatefulWidget {
/// from the list corresponds to the [DropdownMenuItem] of the same index /// from the list corresponds to the [DropdownMenuItem] of the same index
/// in [items]. /// in [items].
/// ///
/// {@tool dartpad --template=stateful_widget_scaffold_no_null_safety} /// {@tool dartpad --template=stateful_widget_scaffold}
/// ///
/// This sample shows a `DropdownButton` with a button with [Text] that /// This sample shows a `DropdownButton` with a button with [Text] that
/// corresponds to but is unique from [DropdownMenuItem]. /// corresponds to but is unique from [DropdownMenuItem].
...@@ -927,7 +927,7 @@ class DropdownButton<T> extends StatefulWidget { ...@@ -927,7 +927,7 @@ class DropdownButton<T> extends StatefulWidget {
/// padding: const EdgeInsets.symmetric(horizontal: 12.0), /// padding: const EdgeInsets.symmetric(horizontal: 12.0),
/// child: DropdownButton<String>( /// child: DropdownButton<String>(
/// value: selectedItem, /// value: selectedItem,
/// onChanged: (String string) => setState(() => selectedItem = string), /// onChanged: (String? string) => setState(() => selectedItem = string!),
/// selectedItemBuilder: (BuildContext context) { /// selectedItemBuilder: (BuildContext context) {
/// return items.map<Widget>((String item) { /// return items.map<Widget>((String item) {
/// return Text(item); /// return Text(item);
...@@ -963,7 +963,7 @@ class DropdownButton<T> extends StatefulWidget { ...@@ -963,7 +963,7 @@ class DropdownButton<T> extends StatefulWidget {
/// To use a separate text style for selected item when it's displayed within /// To use a separate text style for selected item when it's displayed within
/// the dropdown button, consider using [selectedItemBuilder]. /// the dropdown button, consider using [selectedItemBuilder].
/// ///
/// {@tool dartpad --template=stateful_widget_scaffold_no_null_safety} /// {@tool dartpad --template=stateful_widget_scaffold}
/// ///
/// This sample shows a `DropdownButton` with a dropdown button text style /// This sample shows a `DropdownButton` with a dropdown button text style
/// that is different than its menu items. /// that is different than its menu items.
...@@ -979,9 +979,9 @@ class DropdownButton<T> extends StatefulWidget { ...@@ -979,9 +979,9 @@ class DropdownButton<T> extends StatefulWidget {
/// color: Colors.blue, /// color: Colors.blue,
/// child: DropdownButton<String>( /// child: DropdownButton<String>(
/// value: dropdownValue, /// value: dropdownValue,
/// onChanged: (String newValue) { /// onChanged: (String? newValue) {
/// setState(() { /// setState(() {
/// dropdownValue = newValue; /// dropdownValue = newValue!;
/// }); /// });
/// }, /// },
/// style: TextStyle(color: Colors.blue), /// style: TextStyle(color: Colors.blue),
......
...@@ -58,7 +58,7 @@ class _DefaultHeroTag { ...@@ -58,7 +58,7 @@ class _DefaultHeroTag {
/// disabled. Consider changing the [backgroundColor] if disabling the floating /// disabled. Consider changing the [backgroundColor] if disabling the floating
/// action button. /// action button.
/// ///
/// {@tool dartpad --template=stateless_widget_material_no_null_safety} /// {@tool dartpad --template=stateless_widget_material}
/// This example shows how to display a [FloatingActionButton] in a /// This example shows how to display a [FloatingActionButton] in a
/// [Scaffold], with a pink [backgroundColor] and a thumbs up [Icon]. /// [Scaffold], with a pink [backgroundColor] and a thumbs up [Icon].
/// ///
...@@ -85,7 +85,7 @@ class _DefaultHeroTag { ...@@ -85,7 +85,7 @@ class _DefaultHeroTag {
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
/// ///
/// {@tool dartpad --template=stateless_widget_material_no_null_safety} /// {@tool dartpad --template=stateless_widget_material}
/// This example shows how to make an extended [FloatingActionButton] in a /// This example shows how to make an extended [FloatingActionButton] in a
/// [Scaffold], with a pink [backgroundColor], a thumbs up [Icon] and a /// [Scaffold], with a pink [backgroundColor], a thumbs up [Icon] and a
/// [Text] label that reads "Approve". /// [Text] label that reads "Approve".
......
...@@ -30,7 +30,7 @@ const double _kInnerRadius = 4.5; ...@@ -30,7 +30,7 @@ const double _kInnerRadius = 4.5;
/// will respond to [onChanged] by calling [State.setState] to update the /// will respond to [onChanged] by calling [State.setState] to update the
/// radio button's [groupValue]. /// radio button's [groupValue].
/// ///
/// {@tool dartpad --template=stateful_widget_scaffold_center_no_null_safety} /// {@tool dartpad --template=stateful_widget_scaffold_center}
/// ///
/// Here is an example of Radio widgets wrapped in ListTiles, which is similar /// Here is an example of Radio widgets wrapped in ListTiles, which is similar
/// to what you could get with the RadioListTile widget. /// to what you could get with the RadioListTile widget.
...@@ -52,7 +52,7 @@ const double _kInnerRadius = 4.5; ...@@ -52,7 +52,7 @@ const double _kInnerRadius = 4.5;
/// ``` /// ```
/// ///
/// ```dart /// ```dart
/// SingingCharacter _character = SingingCharacter.lafayette; /// SingingCharacter? _character = SingingCharacter.lafayette;
/// ///
/// Widget build(BuildContext context) { /// Widget build(BuildContext context) {
/// return Column( /// return Column(
...@@ -62,7 +62,7 @@ const double _kInnerRadius = 4.5; ...@@ -62,7 +62,7 @@ const double _kInnerRadius = 4.5;
/// leading: Radio( /// leading: Radio(
/// value: SingingCharacter.lafayette, /// value: SingingCharacter.lafayette,
/// groupValue: _character, /// groupValue: _character,
/// onChanged: (SingingCharacter value) { /// onChanged: (SingingCharacter? value) {
/// setState(() { _character = value; }); /// setState(() { _character = value; });
/// }, /// },
/// ), /// ),
...@@ -72,7 +72,7 @@ const double _kInnerRadius = 4.5; ...@@ -72,7 +72,7 @@ const double _kInnerRadius = 4.5;
/// leading: Radio( /// leading: Radio(
/// value: SingingCharacter.jefferson, /// value: SingingCharacter.jefferson,
/// groupValue: _character, /// groupValue: _character,
/// onChanged: (SingingCharacter value) { /// onChanged: (SingingCharacter? value) {
/// setState(() { _character = value; }); /// setState(() { _character = value; });
/// }, /// },
/// ), /// ),
...@@ -202,12 +202,12 @@ class Radio<T> extends StatefulWidget { ...@@ -202,12 +202,12 @@ class Radio<T> extends StatefulWidget {
/// ///
/// The default is false. /// The default is false.
/// ///
/// {@tool dartpad --template=stateful_widget_scaffold_no_null_safety} /// {@tool dartpad --template=stateful_widget_scaffold}
/// This example shows how to enable deselecting a radio button by setting the /// This example shows how to enable deselecting a radio button by setting the
/// [toggleable] attribute. /// [toggleable] attribute.
/// ///
/// ```dart /// ```dart
/// int groupValue; /// int? groupValue;
/// static const List<String> selections = <String>[ /// static const List<String> selections = <String>[
/// 'Hercules Mulligan', /// 'Hercules Mulligan',
/// 'Eliza Hamilton', /// 'Eliza Hamilton',
...@@ -231,7 +231,7 @@ class Radio<T> extends StatefulWidget { ...@@ -231,7 +231,7 @@ class Radio<T> extends StatefulWidget {
/// // TRY THIS: Try setting the toggleable value to false and /// // TRY THIS: Try setting the toggleable value to false and
/// // see how that changes the behavior of the widget. /// // see how that changes the behavior of the widget.
/// toggleable: true, /// toggleable: true,
/// onChanged: (int value) { /// onChanged: (int? value) {
/// setState(() { /// setState(() {
/// groupValue = value; /// groupValue = value;
/// }); /// });
......
...@@ -122,7 +122,7 @@ class Step { ...@@ -122,7 +122,7 @@ class Step {
/// to this widget based on some logic triggered by the three callbacks that it /// to this widget based on some logic triggered by the three callbacks that it
/// provides. /// provides.
/// ///
/// {@tool sample --template=stateful_widget_scaffold_center_no_null_safety} /// {@tool sample --template=stateful_widget_scaffold_center}
/// ///
/// ```dart /// ```dart
/// int _index = 0; /// int _index = 0;
...@@ -247,14 +247,14 @@ class Stepper extends StatefulWidget { ...@@ -247,14 +247,14 @@ class Stepper extends StatefulWidget {
/// For example, keeping track of the [currentStep] within the callback can /// For example, keeping track of the [currentStep] within the callback can
/// change the text of the continue or cancel button depending on which step users are at. /// change the text of the continue or cancel button depending on which step users are at.
/// ///
/// {@tool dartpad --template=stateless_widget_scaffold_no_null_safety} /// {@tool dartpad --template=stateless_widget_scaffold}
/// Creates a stepper control with custom buttons. /// Creates a stepper control with custom buttons.
/// ///
/// ```dart /// ```dart
/// Widget build(BuildContext context) { /// Widget build(BuildContext context) {
/// return Stepper( /// return Stepper(
/// controlsBuilder: /// controlsBuilder:
/// (BuildContext context, { VoidCallback onStepContinue, VoidCallback onStepCancel }) { /// (BuildContext context, { VoidCallback? onStepContinue, VoidCallback? onStepCancel }) {
/// return Row( /// return Row(
/// children: <Widget>[ /// children: <Widget>[
/// TextButton( /// TextButton(
......
...@@ -10,7 +10,6 @@ import 'theme.dart'; ...@@ -10,7 +10,6 @@ import 'theme.dart';
import 'theme_data.dart'; import 'theme_data.dart';
// Examples can assume: // Examples can assume:
// // @dart = 2.9
// void setState(VoidCallback fn) { } // void setState(VoidCallback fn) { }
// bool _isSelected; // bool _isSelected;
...@@ -46,7 +45,7 @@ enum _SwitchListTileType { material, adaptive } ...@@ -46,7 +45,7 @@ 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 dartpad --template=stateful_widget_scaffold_center_no_null_safety} /// {@tool dartpad --template=stateful_widget_scaffold_center}
/// ///
/// ![SwitchListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile.png) /// ![SwitchListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile.png)
/// ///
...@@ -85,7 +84,7 @@ enum _SwitchListTileType { material, adaptive } ...@@ -85,7 +84,7 @@ enum _SwitchListTileType { material, adaptive }
/// into one. Therefore, it may be necessary to create a custom radio tile /// into one. Therefore, it may be necessary to create a custom radio tile
/// widget to accommodate similar use cases. /// widget to accommodate similar use cases.
/// ///
/// {@tool dartpad --template=stateful_widget_scaffold_center_no_null_safety} /// {@tool dartpad --template=stateful_widget_scaffold_center}
/// ///
/// ![Switch list tile semantics sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile_semantics.png) /// ![Switch list tile semantics sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile_semantics.png)
/// ///
...@@ -99,10 +98,10 @@ enum _SwitchListTileType { material, adaptive } ...@@ -99,10 +98,10 @@ enum _SwitchListTileType { material, adaptive }
/// ```dart preamble /// ```dart preamble
/// class LinkedLabelSwitch extends StatelessWidget { /// class LinkedLabelSwitch extends StatelessWidget {
/// const LinkedLabelSwitch({ /// const LinkedLabelSwitch({
/// this.label, /// required this.label,
/// this.padding, /// required this.padding,
/// this.value, /// required this.value,
/// this.onChanged, /// required this.onChanged,
/// }); /// });
/// ///
/// final String label; /// final String label;
...@@ -169,7 +168,7 @@ enum _SwitchListTileType { material, adaptive } ...@@ -169,7 +168,7 @@ enum _SwitchListTileType { material, adaptive }
/// combining [Switch] with other widgets, such as [Text], [Padding] and /// combining [Switch] with other widgets, such as [Text], [Padding] and
/// [InkWell]. /// [InkWell].
/// ///
/// {@tool dartpad --template=stateful_widget_scaffold_center_no_null_safety} /// {@tool dartpad --template=stateful_widget_scaffold_center}
/// ///
/// ![Custom switch list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile_custom.png) /// ![Custom switch list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile_custom.png)
/// ///
...@@ -179,16 +178,14 @@ enum _SwitchListTileType { material, adaptive } ...@@ -179,16 +178,14 @@ enum _SwitchListTileType { material, adaptive }
/// ```dart preamble /// ```dart preamble
/// class LabeledSwitch extends StatelessWidget { /// class LabeledSwitch extends StatelessWidget {
/// const LabeledSwitch({ /// const LabeledSwitch({
/// this.label, /// required this.label,
/// this.padding, /// required this.padding,
/// this.groupValue, /// required this.value,
/// this.value, /// required this.onChanged,
/// this.onChanged,
/// }); /// });
/// ///
/// final String label; /// final String label;
/// final EdgeInsets padding; /// final EdgeInsets padding;
/// final bool groupValue;
/// final bool value; /// final bool value;
/// final Function onChanged; /// final Function onChanged;
/// ///
......
...@@ -30,7 +30,7 @@ import 'tooltip_theme.dart'; ...@@ -30,7 +30,7 @@ import 'tooltip_theme.dart';
/// ///
/// {@youtube 560 315 https://www.youtube.com/watch?v=EeEfD5fI-5Q} /// {@youtube 560 315 https://www.youtube.com/watch?v=EeEfD5fI-5Q}
/// ///
/// {@tool dartpad --template=stateless_widget_scaffold_center_no_null_safety} /// {@tool dartpad --template=stateless_widget_scaffold_center}
/// ///
/// This example show a basic [Tooltip] which has a [Text] as child. /// This example show a basic [Tooltip] which has a [Text] as child.
/// [message] contains your label to be shown by the tooltip when /// [message] contains your label to be shown by the tooltip when
...@@ -47,7 +47,7 @@ import 'tooltip_theme.dart'; ...@@ -47,7 +47,7 @@ import 'tooltip_theme.dart';
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
/// ///
/// {@tool dartpad --template=stateless_widget_scaffold_center_no_null_safety} /// {@tool dartpad --template=stateless_widget_scaffold_center}
/// ///
/// This example covers most of the attributes available in Tooltip. /// This example covers most of the attributes available in Tooltip.
/// `decoration` has been used to give a gradient and borderRadius to Tooltip. /// `decoration` has been used to give a gradient and borderRadius to Tooltip.
......
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