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

[NNBD] Migrate sample code pt 5 (#72845)

parent b21e08c8
......@@ -48,7 +48,7 @@ class _ActiveItem implements Comparable<_ActiveItem> {
///
/// {@youtube 560 315 https://www.youtube.com/watch?v=ZtfItHwFlZ8}
///
/// {@tool dartpad --template=freeform_no_null_safety}
/// {@tool dartpad --template=freeform}
/// This sample application uses an [AnimatedList] to create an effect when
/// items are removed or added to the list.
///
......@@ -65,9 +65,9 @@ class _ActiveItem implements Comparable<_ActiveItem> {
///
/// class _AnimatedListSampleState extends State<AnimatedListSample> {
/// final GlobalKey<AnimatedListState> _listKey = GlobalKey<AnimatedListState>();
/// ListModel<int> _list;
/// int _selectedItem;
/// int _nextItem; // The next item inserted when the user presses the '+' button.
/// late ListModel<int> _list;
/// int? _selectedItem;
/// late int _nextItem; // The next item inserted when the user presses the '+' button.
///
/// @override
/// void initState() {
......@@ -111,14 +111,14 @@ class _ActiveItem implements Comparable<_ActiveItem> {
///
/// // Insert the "next item" into the list model.
/// void _insert() {
/// final int index = _selectedItem == null ? _list.length : _list.indexOf(_selectedItem);
/// final int index = _selectedItem == null ? _list.length : _list.indexOf(_selectedItem!);
/// _list.insert(index, _nextItem++);
/// }
///
/// // Remove the selected item from the list model.
/// void _remove() {
/// if (_selectedItem != null) {
/// _list.removeAt(_list.indexOf(_selectedItem));
/// _list.removeAt(_list.indexOf(_selectedItem!));
/// setState(() {
/// _selectedItem = null;
/// });
......@@ -168,30 +168,30 @@ class _ActiveItem implements Comparable<_ActiveItem> {
/// /// of [AnimatedListState.insertItem] and [AnimatedList.removeItem].
/// class ListModel<E> {
/// ListModel({
/// @required this.listKey,
/// @required this.removedItemBuilder,
/// Iterable<E> initialItems,
/// }) : assert(listKey != null),
/// assert(removedItemBuilder != null),
/// _items = List<E>.from(initialItems ?? <E>[]);
/// required this.listKey,
/// required this.removedItemBuilder,
/// Iterable<E>? initialItems,
/// }) : _items = List<E>.from(initialItems ?? <E>[]);
///
/// final GlobalKey<AnimatedListState> listKey;
/// final dynamic removedItemBuilder;
/// final List<E> _items;
///
/// AnimatedListState get _animatedList => listKey.currentState;
/// AnimatedListState? get _animatedList => listKey.currentState;
///
/// void insert(int index, E item) {
/// _items.insert(index, item);
/// _animatedList.insertItem(index);
/// _animatedList!.insertItem(index);
/// }
///
/// E removeAt(int index) {
/// final E removedItem = _items.removeAt(index);
/// if (removedItem != null) {
/// _animatedList.removeItem(
/// _animatedList!.removeItem(
/// index,
/// (BuildContext context, Animation<double> animation) => removedItemBuilder(removedItem, context, animation),
/// (BuildContext context, Animation<double> animation) {
/// return removedItemBuilder(removedItem, context, animation);
/// },
/// );
/// }
/// return removedItem;
......@@ -212,24 +212,22 @@ class _ActiveItem implements Comparable<_ActiveItem> {
/// /// varies from 0 to 128 as the animation varies from 0.0 to 1.0.
/// class CardItem extends StatelessWidget {
/// const CardItem({
/// Key key,
/// @required this.animation,
/// Key? key,
/// this.onTap,
/// @required this.item,
/// this.selected: false
/// }) : assert(animation != null),
/// assert(item != null && item >= 0),
/// assert(selected != null),
/// this.selected = false,
/// required this.animation,
/// required this.item,
/// }) : assert(item >= 0),
/// super(key: key);
///
/// final Animation<double> animation;
/// final VoidCallback onTap;
/// final VoidCallback? onTap;
/// final int item;
/// final bool selected;
///
/// @override
/// Widget build(BuildContext context) {
/// TextStyle textStyle = Theme.of(context).textTheme.headline4;
/// TextStyle textStyle = Theme.of(context).textTheme.headline4!;
/// if (selected)
/// textStyle = textStyle.copyWith(color: Colors.lightGreenAccent[400]);
/// return Padding(
......@@ -517,7 +515,7 @@ class AnimatedListState extends State<AnimatedList> with TickerProviderStateMixi
/// [GlobalKey] or use the static [SliverAnimatedList.of] method from an item's
/// input callback.
///
/// {@tool dartpad --template=freeform_no_null_safety}
/// {@tool dartpad --template=freeform}
/// This sample application uses a [SliverAnimatedList] to create an animated
/// effect when items are removed or added to the list.
///
......@@ -538,9 +536,9 @@ class AnimatedListState extends State<AnimatedList> with TickerProviderStateMixi
/// final GlobalKey<SliverAnimatedListState> _listKey = GlobalKey<SliverAnimatedListState>();
/// final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
/// final GlobalKey<ScaffoldMessengerState> _scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
/// ListModel<int> _list;
/// int _selectedItem;
/// int _nextItem; // The next item inserted when the user presses the '+' button.
/// late ListModel<int> _list;
/// int? _selectedItem;
/// late int _nextItem; // The next item inserted when the user presses the '+' button.
///
/// @override
/// void initState() {
......@@ -583,19 +581,19 @@ class AnimatedListState extends State<AnimatedList> with TickerProviderStateMixi
///
/// // Insert the "next item" into the list model.
/// void _insert() {
/// final int index = _selectedItem == null ? _list.length : _list.indexOf(_selectedItem);
/// final int index = _selectedItem == null ? _list.length : _list.indexOf(_selectedItem!);
/// _list.insert(index, _nextItem++);
/// }
///
/// // Remove the selected item from the list model.
/// void _remove() {
/// if (_selectedItem != null) {
/// _list.removeAt(_list.indexOf(_selectedItem));
/// _list.removeAt(_list.indexOf(_selectedItem!));
/// setState(() {
/// _selectedItem = null;
/// });
/// } else {
/// _scaffoldMessengerKey.currentState.showSnackBar(SnackBar(
/// _scaffoldMessengerKey.currentState!.showSnackBar(SnackBar(
/// content: Text(
/// 'Select an item to remove from the list.',
/// style: TextStyle(fontSize: 20),
......@@ -658,18 +656,16 @@ class AnimatedListState extends State<AnimatedList> with TickerProviderStateMixi
/// // of [AnimatedListState.insertItem] and [AnimatedList.removeItem].
/// class ListModel<E> {
/// ListModel({
/// @required this.listKey,
/// @required this.removedItemBuilder,
/// Iterable<E> initialItems,
/// }) : assert(listKey != null),
/// assert(removedItemBuilder != null),
/// _items = List<E>.from(initialItems ?? <E>[]);
/// required this.listKey,
/// required this.removedItemBuilder,
/// Iterable<E>? initialItems,
/// }) : _items = List<E>.from(initialItems ?? <E>[]);
///
/// final GlobalKey<SliverAnimatedListState> listKey;
/// final dynamic removedItemBuilder;
/// final List<E> _items;
///
/// SliverAnimatedListState get _animatedList => listKey.currentState;
/// SliverAnimatedListState get _animatedList => listKey.currentState!;
///
/// void insert(int index, E item) {
/// _items.insert(index, item);
......@@ -702,18 +698,16 @@ class AnimatedListState extends State<AnimatedList> with TickerProviderStateMixi
/// // transitions from 0.0 to 1.0.
/// class CardItem extends StatelessWidget {
/// const CardItem({
/// Key key,
/// @required this.animation,
/// @required this.item,
/// Key? key,
/// this.onTap,
/// this.selected = false,
/// }) : assert(animation != null),
/// assert(item != null && item >= 0),
/// assert(selected != null),
/// required this.animation,
/// required this.item,
/// }) : assert(item >= 0),
/// super(key: key);
///
/// final Animation<double> animation;
/// final VoidCallback onTap;
/// final VoidCallback? onTap;
/// final int item;
/// final bool selected;
///
......
......@@ -11,7 +11,7 @@ import 'framework.dart';
/// Animated widget that automatically transitions its size over a given
/// duration whenever the given child's size changes.
///
/// {@tool dartpad --template=stateful_widget_scaffold_center_freeform_state_no_null_safety}
/// {@tool dartpad --template=stateful_widget_scaffold_center_freeform_state}
/// This example makes a [Container] react to being touched, causing the child
/// of the [AnimatedSize] widget, here a [FlutterLogo], to animate.
///
......
......@@ -51,7 +51,7 @@ enum AutofillContextAction {
/// autofillable input fields in an [AutofillGroup], so the user input of the
/// [Form] can be saved for future autofill by the platform.
///
/// {@tool dartpad --template=stateful_widget_scaffold_no_null_safety}
/// {@tool dartpad --template=stateful_widget_scaffold}
///
/// An example form with autofillable fields grouped into different
/// `AutofillGroup`s.
......@@ -92,8 +92,10 @@ enum AutofillContextAction {
/// const Text('Billing address'),
/// Checkbox(
/// value: isSameAddress,
/// onChanged: (bool newValue) {
/// setState(() { isSameAddress = newValue; });
/// onChanged: (bool? newValue) {
/// if (newValue != null) {
/// setState(() { isSameAddress = newValue; });
/// }
/// },
/// ),
/// // Again the address fields are grouped together for the same reason.
......
......@@ -65,7 +65,7 @@ enum DismissDirection {
///
/// {@youtube 560 315 https://www.youtube.com/watch?v=iEMgjrfuc58}
///
/// {@tool dartpad --template=stateful_widget_scaffold_no_null_safety}
/// {@tool dartpad --template=stateful_widget_scaffold}
///
/// This sample shows how you can use the [Dismissible] widget to
/// remove list items using swipe gestures. Swipe any of the list
......
......@@ -48,7 +48,7 @@ import 'inherited_notifier.dart';
/// the focus traversal order, call `Focus.of(context).nextFocus()`. To unfocus
/// a widget, call `Focus.of(context).unfocus()`.
///
/// {@tool dartpad --template=stateful_widget_scaffold_no_null_safety}
/// {@tool dartpad --template=stateful_widget_scaffold}
/// This example shows how to manage focus using the [Focus] and [FocusScope]
/// widgets. See [FocusNode] for a similar example that doesn't use [Focus] or
/// [FocusScope].
......@@ -93,7 +93,7 @@ import 'inherited_notifier.dart';
/// debugLabel: 'Scope',
/// autofocus: true,
/// child: DefaultTextStyle(
/// style: textTheme.headline4,
/// style: textTheme.headline4!,
/// child: Focus(
/// onKey: _handleKeyPress,
/// debugLabel: 'Button',
......@@ -128,7 +128,7 @@ import 'inherited_notifier.dart';
/// ```
/// {@end-tool}
///
/// {@tool dartpad --template=stateless_widget_material_no_null_safety}
/// {@tool dartpad --template=stateless_widget_material}
/// This example shows how to wrap another widget in a [Focus] widget to make it
/// focusable. It wraps a [Container], and changes the container's color when it
/// is set as the [FocusManager.primaryFocus].
......@@ -139,7 +139,10 @@ import 'inherited_notifier.dart';
///
/// ```dart preamble
/// class FocusableText extends StatelessWidget {
/// const FocusableText(this.data, {Key key, this.autofocus}) : super(key: key);
/// const FocusableText(this.data, {
/// Key? key,
/// required this.autofocus,
/// }) : super(key: key);
///
/// /// The string to display as the text for this widget.
/// final String data;
......@@ -186,7 +189,7 @@ import 'inherited_notifier.dart';
/// ```
/// {@end-tool}
///
/// {@tool dartpad --template=stateful_widget_material_no_null_safety}
/// {@tool dartpad --template=stateful_widget_material}
/// This example shows how to focus a newly-created widget immediately after it
/// is created.
///
......@@ -738,7 +741,7 @@ class _FocusState extends State<Focus> {
/// the focus traversal order, call `Focus.of(context).nextFocus()`. To unfocus
/// a widget, call `Focus.of(context).unfocus()`.
///
/// {@tool dartpad --template=stateful_widget_material_no_null_safety}
/// {@tool dartpad --template=stateful_widget_material}
/// This example demonstrates using a [FocusScope] to restrict focus to a particular
/// portion of the app. In this case, restricting focus to the visible part of a
/// Stack.
......@@ -749,19 +752,19 @@ class _FocusState extends State<Focus> {
/// /// This is just a separate widget to simplify the example.
/// class Pane extends StatelessWidget {
/// const Pane({
/// Key key,
/// this.focusNode,
/// Key? key,
/// required this.focusNode,
/// this.onPressed,
/// required this.backgroundColor,
/// required this.icon,
/// this.child,
/// this.backgroundColor,
/// this.icon,
/// }) : super(key: key);
///
/// final FocusNode focusNode;
/// final VoidCallback onPressed;
/// final Widget child;
/// final VoidCallback? onPressed;
/// final Color backgroundColor;
/// final Widget icon;
/// final Widget? child;
///
/// @override
/// Widget build(BuildContext context) {
......@@ -835,7 +838,7 @@ class _FocusState extends State<Focus> {
/// child: Text('ANOTHER BUTTON TO FOCUS'),
/// ),
/// DefaultTextStyle(
/// style: Theme.of(context).textTheme.headline2,
/// style: Theme.of(context).textTheme.headline2!,
/// child: Text('BACKDROP')),
/// ],
/// ),
......@@ -864,7 +867,7 @@ class _FocusState extends State<Focus> {
/// ? null
/// : () => setState(() => backdropIsVisible = true),
/// child: DefaultTextStyle(
/// style: Theme.of(context).textTheme.headline2,
/// style: Theme.of(context).textTheme.headline2!,
/// child: Text('FOREGROUND')),
/// ),
/// ),
......
......@@ -44,7 +44,7 @@ enum OverflowBarAlignment {
/// If the layout overflows, then children's order within their
/// column is specified by [overflowDirection] instead.
///
/// {@tool dartpad --template=stateless_widget_scaffold_center_no_null_safety}
/// {@tool dartpad --template=stateless_widget_scaffold_center}
///
/// This example defines a simple approximation of a dialog
/// layout, where the layout of the dialog's action buttons are
......
......@@ -203,7 +203,7 @@ class _RenderSliverFractionalPadding extends RenderSliverEdgeInsetsPadding {
/// of space that has been scrolled beforehand has not exceeded the main axis
/// extent of the viewport.
///
/// {@tool dartpad --template=stateless_widget_scaffold_no_null_safety}
/// {@tool dartpad --template=stateless_widget_scaffold}
///
/// In this sample the [SliverFillRemaining] sizes its [child] to fill the
/// remaining extent of the viewport in both axes. The icon is centered in the
......@@ -239,7 +239,7 @@ class _RenderSliverFractionalPadding extends RenderSliverEdgeInsetsPadding {
/// [SliverFillRemaining] will defer to the size of its [child] if the
/// child's size exceeds the remaining space in the viewport.
///
/// {@tool dartpad --template=stateless_widget_scaffold_no_null_safety}
/// {@tool dartpad --template=stateless_widget_scaffold}
///
/// In this sample the [SliverFillRemaining] defers to the size of its [child]
/// because the child's extent exceeds that of the remaining extent of the
......@@ -281,7 +281,7 @@ class _RenderSliverFractionalPadding extends RenderSliverEdgeInsetsPadding {
/// [SliverFillRemaining] will defer to the size of its [child] if the
/// [SliverConstraints.precedingScrollExtent] exceeded the length of the viewport's main axis.
///
/// {@tool dartpad --template=stateless_widget_scaffold_no_null_safety}
/// {@tool dartpad --template=stateless_widget_scaffold}
///
/// In this sample the [SliverFillRemaining] defers to the size of its [child]
/// because the [SliverConstraints.precedingScrollExtent] has gone
......@@ -330,7 +330,7 @@ class _RenderSliverFractionalPadding extends RenderSliverEdgeInsetsPadding {
///
/// {@animation 250 500 https://flutter.github.io/assets-for-api-docs/assets/widgets/sliver_fill_remaining_fill_overscroll.mp4}
///
/// {@tool sample --template=stateless_widget_scaffold_no_null_safety}
/// {@tool sample --template=stateless_widget_scaffold}
///
/// In this sample the [SliverFillRemaining]'s child stretches to fill the
/// overscroll area when [fillOverscroll] is true. This sample also features a
......
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