From dafc13f11d073fb53715f60bf4e1e10d5718fdd3 Mon Sep 17 00:00:00 2001 From: Shi-Hao Hong Date: Wed, 23 Dec 2020 08:44:10 +0800 Subject: [PATCH] [NNBD] Migrate sample code pt 2 (#72798) --- .../lib/src/material/checkbox_list_tile.dart | 31 +++++++++---------- .../flutter/lib/src/material/dropdown.dart | 16 +++++----- .../src/material/floating_action_button.dart | 4 +-- packages/flutter/lib/src/material/radio.dart | 14 ++++----- .../flutter/lib/src/material/stepper.dart | 6 ++-- .../lib/src/material/switch_list_tile.dart | 25 +++++++-------- .../flutter/lib/src/material/tooltip.dart | 4 +-- 7 files changed, 48 insertions(+), 52 deletions(-) diff --git a/packages/flutter/lib/src/material/checkbox_list_tile.dart b/packages/flutter/lib/src/material/checkbox_list_tile.dart index f94b3d07e7..892045fa2c 100644 --- a/packages/flutter/lib/src/material/checkbox_list_tile.dart +++ b/packages/flutter/lib/src/material/checkbox_list_tile.dart @@ -10,7 +10,6 @@ import 'theme.dart'; import 'theme_data.dart'; // Examples can assume: -// // @dart = 2.9 // void setState(VoidCallback fn) { } /// A [ListTile] with a [Checkbox]. In other words, a checkbox with a label. @@ -40,7 +39,7 @@ import 'theme_data.dart'; /// To show the [CheckboxListTile] as disabled, pass null as the [onChanged] /// 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) /// @@ -59,8 +58,8 @@ import 'theme_data.dart'; /// return CheckboxListTile( /// title: const Text('Animate Slowly'), /// value: timeDilation != 1.0, -/// onChanged: (bool value) { -/// setState(() { timeDilation = value ? 10.0 : 1.0; }); +/// onChanged: (bool? value) { +/// setState(() { timeDilation = value! ? 10.0 : 1.0; }); /// }, /// secondary: const Icon(Icons.hourglass_empty), /// ); @@ -85,7 +84,7 @@ import 'theme_data.dart'; /// into one. Therefore, it may be necessary to create a custom radio tile /// 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) /// @@ -99,10 +98,10 @@ import 'theme_data.dart'; /// ```dart preamble /// class LinkedLabelCheckbox extends StatelessWidget { /// const LinkedLabelCheckbox({ -/// this.label, -/// this.padding, -/// this.value, -/// this.onChanged, +/// required this.label, +/// required this.padding, +/// required this.value, +/// required this.onChanged, /// }); /// /// final String label; @@ -133,7 +132,7 @@ import 'theme_data.dart'; /// ), /// Checkbox( /// value: value, -/// onChanged: (bool newValue) { +/// onChanged: (bool? newValue) { /// onChanged(newValue); /// }, /// ), @@ -169,7 +168,7 @@ import 'theme_data.dart'; /// combining [Checkbox] with other widgets, such as [Text], [Padding] and /// [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) /// @@ -179,10 +178,10 @@ import 'theme_data.dart'; /// ```dart preamble /// class LabeledCheckbox extends StatelessWidget { /// const LabeledCheckbox({ -/// this.label, -/// this.padding, -/// this.value, -/// this.onChanged, +/// required this.label, +/// required this.padding, +/// required this.value, +/// required this.onChanged, /// }); /// /// final String label; @@ -203,7 +202,7 @@ import 'theme_data.dart'; /// Expanded(child: Text(label)), /// Checkbox( /// value: value, -/// onChanged: (bool newValue) { +/// onChanged: (bool? newValue) { /// onChanged(newValue); /// }, /// ), diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index fea4feaa0b..aa4fea655c 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -728,7 +728,7 @@ class DropdownButtonHideUnderline extends InheritedWidget { /// dropdown's value. It should also call [State.setState] to rebuild the /// 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, /// purple text style, and bold purple underline, whose value is one of "One", @@ -753,9 +753,9 @@ class DropdownButtonHideUnderline extends InheritedWidget { /// height: 2, /// color: Colors.deepPurpleAccent, /// ), -/// onChanged: (String newValue) { +/// onChanged: (String? newValue) { /// setState(() { -/// dropdownValue = newValue; +/// dropdownValue = newValue!; /// }); /// }, /// items: ['One', 'Two', 'Free', 'Four'] @@ -912,7 +912,7 @@ class DropdownButton extends StatefulWidget { /// from the list corresponds to the [DropdownMenuItem] of the same index /// 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 /// corresponds to but is unique from [DropdownMenuItem]. @@ -927,7 +927,7 @@ class DropdownButton extends StatefulWidget { /// padding: const EdgeInsets.symmetric(horizontal: 12.0), /// child: DropdownButton( /// value: selectedItem, - /// onChanged: (String string) => setState(() => selectedItem = string), + /// onChanged: (String? string) => setState(() => selectedItem = string!), /// selectedItemBuilder: (BuildContext context) { /// return items.map((String item) { /// return Text(item); @@ -963,7 +963,7 @@ class DropdownButton extends StatefulWidget { /// To use a separate text style for selected item when it's displayed within /// 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 /// that is different than its menu items. @@ -979,9 +979,9 @@ class DropdownButton extends StatefulWidget { /// color: Colors.blue, /// child: DropdownButton( /// value: dropdownValue, - /// onChanged: (String newValue) { + /// onChanged: (String? newValue) { /// setState(() { - /// dropdownValue = newValue; + /// dropdownValue = newValue!; /// }); /// }, /// style: TextStyle(color: Colors.blue), diff --git a/packages/flutter/lib/src/material/floating_action_button.dart b/packages/flutter/lib/src/material/floating_action_button.dart index a1a7949d9d..d1fdb66c6f 100644 --- a/packages/flutter/lib/src/material/floating_action_button.dart +++ b/packages/flutter/lib/src/material/floating_action_button.dart @@ -58,7 +58,7 @@ class _DefaultHeroTag { /// disabled. Consider changing the [backgroundColor] if disabling the floating /// 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 /// [Scaffold], with a pink [backgroundColor] and a thumbs up [Icon]. /// @@ -85,7 +85,7 @@ class _DefaultHeroTag { /// ``` /// {@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 /// [Scaffold], with a pink [backgroundColor], a thumbs up [Icon] and a /// [Text] label that reads "Approve". diff --git a/packages/flutter/lib/src/material/radio.dart b/packages/flutter/lib/src/material/radio.dart index 5a3d52ed3b..f21e3bb5d4 100644 --- a/packages/flutter/lib/src/material/radio.dart +++ b/packages/flutter/lib/src/material/radio.dart @@ -30,7 +30,7 @@ const double _kInnerRadius = 4.5; /// will respond to [onChanged] by calling [State.setState] to update the /// 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 /// to what you could get with the RadioListTile widget. @@ -52,7 +52,7 @@ const double _kInnerRadius = 4.5; /// ``` /// /// ```dart -/// SingingCharacter _character = SingingCharacter.lafayette; +/// SingingCharacter? _character = SingingCharacter.lafayette; /// /// Widget build(BuildContext context) { /// return Column( @@ -62,7 +62,7 @@ const double _kInnerRadius = 4.5; /// leading: Radio( /// value: SingingCharacter.lafayette, /// groupValue: _character, -/// onChanged: (SingingCharacter value) { +/// onChanged: (SingingCharacter? value) { /// setState(() { _character = value; }); /// }, /// ), @@ -72,7 +72,7 @@ const double _kInnerRadius = 4.5; /// leading: Radio( /// value: SingingCharacter.jefferson, /// groupValue: _character, -/// onChanged: (SingingCharacter value) { +/// onChanged: (SingingCharacter? value) { /// setState(() { _character = value; }); /// }, /// ), @@ -202,12 +202,12 @@ class Radio extends StatefulWidget { /// /// 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 /// [toggleable] attribute. /// /// ```dart - /// int groupValue; + /// int? groupValue; /// static const List selections = [ /// 'Hercules Mulligan', /// 'Eliza Hamilton', @@ -231,7 +231,7 @@ class Radio extends StatefulWidget { /// // TRY THIS: Try setting the toggleable value to false and /// // see how that changes the behavior of the widget. /// toggleable: true, - /// onChanged: (int value) { + /// onChanged: (int? value) { /// setState(() { /// groupValue = value; /// }); diff --git a/packages/flutter/lib/src/material/stepper.dart b/packages/flutter/lib/src/material/stepper.dart index 2c05cdf683..84d337fec9 100755 --- a/packages/flutter/lib/src/material/stepper.dart +++ b/packages/flutter/lib/src/material/stepper.dart @@ -122,7 +122,7 @@ class Step { /// to this widget based on some logic triggered by the three callbacks that it /// provides. /// -/// {@tool sample --template=stateful_widget_scaffold_center_no_null_safety} +/// {@tool sample --template=stateful_widget_scaffold_center} /// /// ```dart /// int _index = 0; @@ -247,14 +247,14 @@ class Stepper extends StatefulWidget { /// 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. /// - /// {@tool dartpad --template=stateless_widget_scaffold_no_null_safety} + /// {@tool dartpad --template=stateless_widget_scaffold} /// Creates a stepper control with custom buttons. /// /// ```dart /// Widget build(BuildContext context) { /// return Stepper( /// controlsBuilder: - /// (BuildContext context, { VoidCallback onStepContinue, VoidCallback onStepCancel }) { + /// (BuildContext context, { VoidCallback? onStepContinue, VoidCallback? onStepCancel }) { /// return Row( /// children: [ /// TextButton( diff --git a/packages/flutter/lib/src/material/switch_list_tile.dart b/packages/flutter/lib/src/material/switch_list_tile.dart index ffd1ca08e5..db3160229d 100644 --- a/packages/flutter/lib/src/material/switch_list_tile.dart +++ b/packages/flutter/lib/src/material/switch_list_tile.dart @@ -10,7 +10,6 @@ import 'theme.dart'; import 'theme_data.dart'; // Examples can assume: -// // @dart = 2.9 // void setState(VoidCallback fn) { } // bool _isSelected; @@ -46,7 +45,7 @@ enum _SwitchListTileType { material, adaptive } /// To show the [SwitchListTile] as disabled, pass null as the [onChanged] /// 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) /// @@ -85,7 +84,7 @@ enum _SwitchListTileType { material, adaptive } /// into one. Therefore, it may be necessary to create a custom radio tile /// 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) /// @@ -99,10 +98,10 @@ enum _SwitchListTileType { material, adaptive } /// ```dart preamble /// class LinkedLabelSwitch extends StatelessWidget { /// const LinkedLabelSwitch({ -/// this.label, -/// this.padding, -/// this.value, -/// this.onChanged, +/// required this.label, +/// required this.padding, +/// required this.value, +/// required this.onChanged, /// }); /// /// final String label; @@ -169,7 +168,7 @@ enum _SwitchListTileType { material, adaptive } /// combining [Switch] with other widgets, such as [Text], [Padding] and /// [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) /// @@ -179,16 +178,14 @@ enum _SwitchListTileType { material, adaptive } /// ```dart preamble /// class LabeledSwitch extends StatelessWidget { /// const LabeledSwitch({ -/// this.label, -/// this.padding, -/// this.groupValue, -/// this.value, -/// this.onChanged, +/// required this.label, +/// required this.padding, +/// required this.value, +/// required this.onChanged, /// }); /// /// final String label; /// final EdgeInsets padding; -/// final bool groupValue; /// final bool value; /// final Function onChanged; /// diff --git a/packages/flutter/lib/src/material/tooltip.dart b/packages/flutter/lib/src/material/tooltip.dart index 66dc9d2603..db73084885 100644 --- a/packages/flutter/lib/src/material/tooltip.dart +++ b/packages/flutter/lib/src/material/tooltip.dart @@ -30,7 +30,7 @@ import 'tooltip_theme.dart'; /// /// {@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. /// [message] contains your label to be shown by the tooltip when @@ -47,7 +47,7 @@ import 'tooltip_theme.dart'; /// ``` /// {@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. /// `decoration` has been used to give a gradient and borderRadius to Tooltip.