Unverified Commit b9cfe053 authored by Darren Austin's avatar Darren Austin Committed by GitHub

Migrate some material doc samples to null safety. (#72297)

parent 0351c74a
......@@ -9,8 +9,7 @@ import 'theme.dart';
import 'theme_data.dart';
// Examples can assume:
// // @dart = 2.9
// String userAvatarUrl;
// late String userAvatarUrl;
/// A circle that represents a user.
///
......
......@@ -6,9 +6,6 @@ import 'dart:ui' show Color;
import 'package:flutter/painting.dart';
// Examples can assume:
// // @dart = 2.9
/// Defines a single color as well a color swatch with ten shades of the color.
///
/// The color's shades are referred to by index. The greater the index, the
......@@ -113,7 +110,7 @@ class MaterialAccentColor extends ColorSwatch<int> {
/// using an integer for the specific color desired, as follows:
///
/// ```dart
/// Color selection = Colors.green[400]; // Selects a mid-range green.
/// Color selection = Colors.green[400]!; // Selects a mid-range green.
/// ```
/// {@end-tool}
/// {@tool snippet}
......
......@@ -18,9 +18,8 @@ import 'theme.dart';
import 'theme_data.dart';
// Examples can assume:
// // @dart = 2.9
// enum Department { treasury, state }
// BuildContext context;
// late BuildContext context;
const EdgeInsets _defaultInsetPadding = EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0);
......@@ -706,6 +705,9 @@ class SimpleDialogOption extends StatelessWidget {
/// case Department.state:
/// // ...
/// break;
/// case null:
/// // dialog dismissed
/// break;
/// }
/// }
/// ```
......
......@@ -16,9 +16,6 @@ import 'navigation_rail_theme.dart';
import 'theme.dart';
import 'theme_data.dart';
// Examples can assume:
// // @dart = 2.9
/// A material widget that is meant to be displayed at the left or right of an
/// app to navigate between a small number of views, typically between three and
/// five.
......@@ -41,7 +38,7 @@ import 'theme_data.dart';
/// [https://github.com/flutter/samples/blob/master/experimental/web_dashboard/lib/src/widgets/third_party/adaptive_scaffold.dart]
/// for an example.
///
/// {@tool dartpad --template=stateful_widget_material_no_null_safety}
/// {@tool dartpad --template=stateful_widget_material}
///
/// This example shows a [NavigationRail] used within a Scaffold with 3
/// [NavigationRailDestination]s. The main content is separated by a divider
......@@ -350,12 +347,12 @@ class NavigationRail extends StatefulWidget {
/// final Animation<double> animation = NavigationRail.extendedAnimation(context);
/// return AnimatedBuilder(
/// animation: animation,
/// builder: (BuildContext context, Widget child) {
/// builder: (BuildContext context, Widget? child) {
/// // The extended fab has a shorter height than the regular fab.
/// return Container(
/// height: 56,
/// padding: EdgeInsets.symmetric(
/// vertical: lerpDouble(0, 6, animation.value),
/// vertical: lerpDouble(0, 6, animation.value)!,
/// ),
/// child: animation.value == 0
/// ? FloatingActionButton(
......
......@@ -12,7 +12,6 @@ import 'material.dart';
import 'material_localizations.dart';
// Examples can assume:
// // @dart = 2.9
// class MyDataObject { }
/// The callback used by [ReorderableListView] to move an item to a new
......@@ -60,7 +59,7 @@ typedef ReorderCallback = void Function(int oldIndex, int newIndex);
/// The [onReorder] parameter is required and will be called when a child
/// widget is dragged to a new position.
///
/// {@tool dartpad --template=stateful_widget_scaffold_no_null_safety}
/// {@tool dartpad --template=stateful_widget_scaffold}
///
/// ```dart
/// List<String> _list = List.generate(5, (i) => "${i}");
......
......@@ -30,12 +30,11 @@ import 'theme.dart';
import 'theme_data.dart';
// Examples can assume:
// // @dart = 2.9
// TabController tabController;
// late TabController tabController;
// void setState(VoidCallback fn) { }
// String appBarTitle;
// int tabCount;
// TickerProvider tickerProvider;
// late String appBarTitle;
// late int tabCount;
// late TickerProvider tickerProvider;
const FloatingActionButtonLocation _kDefaultFloatingActionButtonLocation = FloatingActionButtonLocation.endFloat;
const FloatingActionButtonAnimator _kDefaultFloatingActionButtonAnimator = FloatingActionButtonAnimator.scaling;
......@@ -69,7 +68,7 @@ enum _ScaffoldSlot {
/// [BuildContext] via [ScaffoldMessenger.of] and use the
/// [ScaffoldMessengerState.showSnackBar] function.
///
/// {@tool dartpad --template=stateless_widget_scaffold_center_no_null_safety}
/// {@tool dartpad --template=stateless_widget_scaffold_center}
///
/// Here is an example of showing a [SnackBar] when the user presses a button.
///
......@@ -112,7 +111,7 @@ class ScaffoldMessenger extends StatefulWidget {
/// The state from the closest instance of this class that encloses the given
/// context.
///
/// {@tool dartpad --template=stateless_widget_scaffold_center_no_null_safety}
/// {@tool dartpad --template=stateless_widget_scaffold_center}
/// Typical usage of the [ScaffoldMessenger.of] function is to call it in
/// response to a user gesture or an application state change.
///
......@@ -138,7 +137,7 @@ class ScaffoldMessenger extends StatefulWidget {
/// function. The [MaterialApp.scaffoldMessengerKey] refers to the root
/// ScaffoldMessenger that is provided by default.
///
/// {@tool dartpad --template=freeform_no_null_safety}
/// {@tool dartpad --template=freeform}
/// Sometimes [SnackBar]s are produced by code that doesn't have ready access
/// to a valid [BuildContext]. One such example of this is when you show a
/// SnackBar from a method outside of the `build` function. In these
......@@ -166,7 +165,7 @@ class ScaffoldMessenger extends StatefulWidget {
/// _counter++;
/// });
/// if (_counter % 10 == 0) {
/// _scaffoldMessengerKey.currentState.showSnackBar(const SnackBar(
/// _scaffoldMessengerKey.currentState!.showSnackBar(const SnackBar(
/// content: Text('A multiple of ten!'),
/// ));
/// }
......@@ -304,7 +303,7 @@ class ScaffoldMessengerState extends State<ScaffoldMessenger> with TickerProvide
/// See [ScaffoldMessenger.of] for information about how to obtain the
/// [ScaffoldMessengerState].
///
/// {@tool dartpad --template=stateless_widget_scaffold_center_no_null_safety}
/// {@tool dartpad --template=stateless_widget_scaffold_center}
///
/// Here is an example of showing a [SnackBar] when the user presses a button.
///
......@@ -1259,7 +1258,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
/// [ScaffoldState] for the current [BuildContext] via [Scaffold.of] and use the
/// [ScaffoldState.showBottomSheet] function.
///
/// {@tool dartpad --template=stateful_widget_material_no_null_safety}
/// {@tool dartpad --template=stateful_widget_material}
/// This example shows a [Scaffold] with a [body] and [FloatingActionButton].
/// The [body] is a [Text] placed in a [Center] in order to center the text
/// within the [Scaffold]. The [FloatingActionButton] is connected to a
......@@ -1288,7 +1287,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
/// ```
/// {@end-tool}
///
/// {@tool dartpad --template=stateful_widget_material_no_null_safety}
/// {@tool dartpad --template=stateful_widget_material}
/// This example shows a [Scaffold] with a blueGrey [backgroundColor], [body]
/// and [FloatingActionButton]. The [body] is a [Text] placed in a [Center] in
/// order to center the text within the [Scaffold]. The [FloatingActionButton]
......@@ -1318,7 +1317,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
/// ```
/// {@end-tool}
///
/// {@tool dartpad --template=stateful_widget_material_no_null_safety}
/// {@tool dartpad --template=stateful_widget_material}
/// This example shows a [Scaffold] with an [AppBar], a [BottomAppBar] and a
/// [FloatingActionButton]. The [body] is a [Text] placed in a [Center] in order
/// to center the text within the [Scaffold]. The [FloatingActionButton] is
......@@ -1560,7 +1559,7 @@ class Scaffold extends StatefulWidget {
///
/// To close the drawer, use [Navigator.pop].
///
/// {@tool dartpad --template=stateful_widget_material_no_null_safety}
/// {@tool dartpad --template=stateful_widget_material}
/// To disable the drawer edge swipe, set the
/// [Scaffold.drawerEnableOpenDragGesture] to false. Then, use
/// [ScaffoldState.openDrawer] to open the drawer and [Navigator.pop] to close
......@@ -1570,7 +1569,7 @@ class Scaffold extends StatefulWidget {
/// final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
///
/// void _openDrawer() {
/// _scaffoldKey.currentState.openDrawer();
/// _scaffoldKey.currentState!.openDrawer();
/// }
///
/// void _closeDrawer() {
......@@ -1623,7 +1622,7 @@ class Scaffold extends StatefulWidget {
///
/// To close the drawer, use [Navigator.pop].
///
/// {@tool dartpad --template=stateful_widget_material_no_null_safety}
/// {@tool dartpad --template=stateful_widget_material}
/// To disable the drawer edge swipe, set the
/// [Scaffold.endDrawerEnableOpenDragGesture] to false. Then, use
/// [ScaffoldState.openEndDrawer] to open the drawer and [Navigator.pop] to
......@@ -1633,7 +1632,7 @@ class Scaffold extends StatefulWidget {
/// final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
///
/// void _openEndDrawer() {
/// _scaffoldKey.currentState.openEndDrawer();
/// _scaffoldKey.currentState!.openEndDrawer();
/// }
///
/// void _closeEndDrawer() {
......@@ -1790,7 +1789,7 @@ class Scaffold extends StatefulWidget {
/// If no instance of this class encloses the given context, will cause an
/// assert in debug mode, and throw an exception in release mode.
///
/// {@tool dartpad --template=freeform_no_null_safety}
/// {@tool dartpad --template=freeform}
/// Typical usage of the [Scaffold.of] function is to call it from within the
/// `build` method of a child of a [Scaffold].
///
......@@ -1861,7 +1860,7 @@ class Scaffold extends StatefulWidget {
/// ```
/// {@end-tool}
///
/// {@tool dartpad --template=stateless_widget_material_no_null_safety}
/// {@tool dartpad --template=stateless_widget_material}
/// When the [Scaffold] is actually created in the same `build` function, the
/// `context` argument to the `build` function can't be used to find the
/// [Scaffold] (since it's "above" the widget being returned in the widget
......@@ -2173,7 +2172,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
/// See [ScaffoldMessenger.of] for information about how to obtain the
/// [ScaffoldMessengerState].
///
/// {@tool dartpad --template=stateless_widget_scaffold_center_no_null_safety}
/// {@tool dartpad --template=stateless_widget_scaffold_center}
///
/// Here is an example of showing a [SnackBar] when the user presses a button.
///
......@@ -2547,7 +2546,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
/// of the app. Modal bottom sheets can be created and displayed with the
/// [showModalBottomSheet] function.
///
/// {@tool dartpad --template=stateless_widget_scaffold_no_null_safety}
/// {@tool dartpad --template=stateless_widget_scaffold}
///
/// This example demonstrates how to use `showBottomSheet` to display a
/// bottom sheet when a user taps a button. It also demonstrates how to
......
......@@ -9,8 +9,7 @@ import 'package:flutter/widgets.dart';
import 'constants.dart';
// Examples can assume:
// // @dart = 2.9
// BuildContext context;
// late BuildContext context;
/// Coordinates tab selection between a [TabBar] and a [TabBarView].
///
......@@ -33,7 +32,7 @@ import 'constants.dart';
///
/// ```dart
/// class MyTabbedPage extends StatefulWidget {
/// const MyTabbedPage({ Key key }) : super(key: key);
/// const MyTabbedPage({ Key? key }) : super(key: key);
/// @override
/// _MyTabbedPageState createState() => _MyTabbedPageState();
/// }
......@@ -44,7 +43,7 @@ import 'constants.dart';
/// Tab(text: 'RIGHT'),
/// ];
///
/// TabController _tabController;
/// late TabController _tabController;
///
/// @override
/// void initState() {
......@@ -70,7 +69,7 @@ import 'constants.dart';
/// body: TabBarView(
/// controller: _tabController,
/// children: myTabs.map((Tab tab) {
/// final String label = tab.text.toLowerCase();
/// final String label = tab.text!.toLowerCase();
/// return Center(
/// child: Text(
/// 'This is the $label tab',
......@@ -85,7 +84,7 @@ import 'constants.dart';
/// ```
/// {@end-tool}
///
/// {@tool dartpad --template=stateless_widget_material_no_null_safety}
/// {@tool dartpad --template=stateless_widget_material}
///
/// This example shows how to listen to page updates in [TabBar] and [TabBarView]
/// when using [DefaultTabController].
......@@ -106,7 +105,7 @@ import 'constants.dart';
/// // closest DefaultTabController.
/// child: Builder(
/// builder: (BuildContext context) {
/// final TabController tabController = DefaultTabController.of(context);
/// final TabController tabController = DefaultTabController.of(context)!;
/// tabController.addListener(() {
/// if (!tabController.indexIsChanging) {
/// // Your code goes here.
......@@ -123,7 +122,7 @@ import 'constants.dart';
/// children: tabs.map((Tab tab){
/// return Center(
/// child: Text(
/// tab.text + ' Tab',
/// tab.text! + ' Tab',
/// style: Theme.of(context).textTheme.headline5,
/// ),
/// );
......@@ -405,7 +404,7 @@ class DefaultTabController extends StatefulWidget {
/// Typical usage is as follows:
///
/// ```dart
/// TabController controller = DefaultTabController.of(context);
/// TabController controller = DefaultTabController.of(context)!;
/// ```
/// {@end-tool}
static TabController? of(BuildContext context) {
......
......@@ -25,9 +25,6 @@ import 'theme.dart';
export 'package:flutter/services.dart' show TextInputType, TextInputAction, TextCapitalization, SmartQuotesType, SmartDashesType;
// Examples can assume:
// // @dart = 2.9
/// Signature for the [TextField.buildCounter] callback.
typedef InputCounterWidgetBuilder = Widget? Function(
/// The build context for the TextField.
......@@ -201,13 +198,13 @@ class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDete
/// callback. This callback is applied to the text field's current value when
/// the user finishes editing.
///
/// {@tool dartpad --template=stateful_widget_material_no_null_safety}
/// {@tool dartpad --template=stateful_widget_material}
///
/// This sample shows how to get a value from a TextField via the [onSubmitted]
/// callback.
///
/// ```dart
/// TextEditingController _controller;
/// late TextEditingController _controller;
///
/// void initState() {
/// super.initState();
......@@ -769,9 +766,9 @@ class TextField extends StatefulWidget {
/// Widget counter(
/// BuildContext context,
/// {
/// int currentLength,
/// int maxLength,
/// bool isFocused,
/// required int currentLength,
/// required int? maxLength,
/// required bool isFocused,
/// }
/// ) {
/// return Text(
......
......@@ -7,9 +7,6 @@ import 'package:flutter/painting.dart';
import 'typography.dart';
// Examples can assume:
// // @dart = 2.9
/// Material design text theme.
///
/// Definitions for the various typographical styles found in Material Design
......@@ -356,7 +353,7 @@ class TextTheme with Diagnosticable {
/// /// A Widget that sets the ambient theme's title text color for its
/// /// descendants, while leaving other ambient theme attributes alone.
/// class TitleColorThemeCopy extends StatelessWidget {
/// TitleColorThemeCopy({Key key, this.child, this.titleColor}) : super(key: key);
/// TitleColorThemeCopy({Key? key, required this.child, required this.titleColor}) : super(key: key);
///
/// final Color titleColor;
/// final Widget child;
......@@ -367,7 +364,7 @@ class TextTheme with Diagnosticable {
/// return Theme(
/// data: theme.copyWith(
/// textTheme: theme.textTheme.copyWith(
/// headline6: theme.textTheme.headline6.copyWith(
/// headline6: theme.textTheme.headline6!.copyWith(
/// color: titleColor,
/// ),
/// ),
......@@ -497,7 +494,7 @@ class TextTheme with Diagnosticable {
/// /// A Widget that sets the ambient theme's title text color for its
/// /// descendants, while leaving other ambient theme attributes alone.
/// class TitleColorTheme extends StatelessWidget {
/// TitleColorTheme({Key key, this.child, this.titleColor}) : super(key: key);
/// TitleColorTheme({Key? key, required this.child, required this.titleColor}) : super(key: key);
///
/// final Color titleColor;
/// final Widget child;
......
......@@ -34,8 +34,7 @@ import 'time.dart';
import 'time_picker_theme.dart';
// Examples can assume:
// // @dart = 2.9
// BuildContext context;
// late BuildContext context;
const Duration _kDialogSizeAnimationDuration = Duration(milliseconds: 200);
const Duration _kDialAnimateDuration = Duration(milliseconds: 200);
......@@ -2127,7 +2126,7 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
/// Show a dialog with [initialTime] equal to the current time.
///
/// ```dart
/// Future<TimeOfDay> selectedTime = showTimePicker(
/// Future<TimeOfDay?> selectedTime = showTimePicker(
/// initialTime: TimeOfDay.now(),
/// context: context,
/// );
......@@ -2156,13 +2155,13 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
/// Show a dialog with the text direction overridden to be [TextDirection.rtl].
///
/// ```dart
/// Future<TimeOfDay> selectedTimeRTL = showTimePicker(
/// Future<TimeOfDay?> selectedTimeRTL = showTimePicker(
/// context: context,
/// initialTime: TimeOfDay.now(),
/// builder: (BuildContext context, Widget child) {
/// builder: (BuildContext context, Widget? child) {
/// return Directionality(
/// textDirection: TextDirection.rtl,
/// child: child,
/// child: child!,
/// );
/// },
/// );
......@@ -2173,13 +2172,13 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
/// Show a dialog with time unconditionally displayed in 24 hour format.
///
/// ```dart
/// Future<TimeOfDay> selectedTime24Hour = showTimePicker(
/// Future<TimeOfDay?> selectedTime24Hour = showTimePicker(
/// context: context,
/// initialTime: TimeOfDay(hour: 10, minute: 47),
/// builder: (BuildContext context, Widget child) {
/// builder: (BuildContext context, Widget? child) {
/// return MediaQuery(
/// data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: true),
/// child: child,
/// child: child!,
/// );
/// },
/// );
......
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