Add maybeOf for all the cases where of returns nullable. (#114120)

This commit is contained in:
Greg Spencer
2022-10-31 16:09:09 -07:00
committed by GitHub
parent b20b7d995b
commit 37b72342b0
73 changed files with 836 additions and 308 deletions

View File

@@ -210,8 +210,8 @@ class _ExpansionPanelsDemoState extends State<ExpansionPanelsDemo> {
builder: (BuildContext context) {
return CollapsibleBody(
margin: const EdgeInsets.symmetric(horizontal: 16.0),
onSave: () { Form.of(context)!.save(); close(); },
onCancel: () { Form.of(context)!.reset(); close(); },
onSave: () { Form.of(context).save(); close(); },
onCancel: () { Form.of(context).reset(); close(); },
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: TextFormField(
@@ -244,8 +244,8 @@ class _ExpansionPanelsDemoState extends State<ExpansionPanelsDemo> {
child: Builder(
builder: (BuildContext context) {
return CollapsibleBody(
onSave: () { Form.of(context)!.save(); close(); },
onCancel: () { Form.of(context)!.reset(); close(); },
onSave: () { Form.of(context).save(); close(); },
onCancel: () { Form.of(context).reset(); close(); },
child: FormField<Location>(
initialValue: item.value,
onSaved: (Location? result) { item.value = result; },
@@ -298,8 +298,8 @@ class _ExpansionPanelsDemoState extends State<ExpansionPanelsDemo> {
child: Builder(
builder: (BuildContext context) {
return CollapsibleBody(
onSave: () { Form.of(context)!.save(); close(); },
onCancel: () { Form.of(context)!.reset(); close(); },
onSave: () { Form.of(context).save(); close(); },
onCancel: () { Form.of(context).reset(); close(); },
child: FormField<double>(
initialValue: item.value,
onSaved: (double? value) { item.value = value; },

View File

@@ -12,7 +12,7 @@ class _PageSelector extends StatelessWidget {
final List<Icon>? icons;
void _handleArrowButtonPress(BuildContext context, int delta) {
final TabController controller = DefaultTabController.of(context)!;
final TabController controller = DefaultTabController.of(context);
if (!controller.indexIsChanging) {
controller.animateTo((controller.index + delta).clamp(0, icons!.length - 1));
}
@@ -20,7 +20,7 @@ class _PageSelector extends StatelessWidget {
@override
Widget build(BuildContext context) {
final TabController? controller = DefaultTabController.of(context);
final TabController? controller = DefaultTabController.maybeOf(context);
final Color color = Theme.of(context).colorScheme.secondary;
return SafeArea(
top: false,

View File

@@ -63,7 +63,7 @@ class TabbedComponentDemoScaffold extends StatefulWidget {
class _TabbedComponentDemoScaffoldState extends State<TabbedComponentDemoScaffold> {
void _showExampleCode(BuildContext context) {
final String? tag = widget.demos![DefaultTabController.of(context)!.index].exampleCodeTag;
final String? tag = widget.demos![DefaultTabController.of(context).index].exampleCodeTag;
if (tag != null) {
Navigator.push(context, MaterialPageRoute<FullScreenCodeDialog>(
builder: (BuildContext context) => FullScreenCodeDialog(exampleCodeTag: tag)
@@ -72,7 +72,7 @@ class _TabbedComponentDemoScaffoldState extends State<TabbedComponentDemoScaffol
}
Future<void> _showApiDocumentation(BuildContext context) async {
final String? url = widget.demos![DefaultTabController.of(context)!.index].documentationUrl;
final String? url = widget.demos![DefaultTabController.of(context).index].documentationUrl;
if (url == null) {
return;
}

View File

@@ -451,7 +451,7 @@ class _AnimationDemoState extends State<AnimationDemo> with TickerProviderStateM
return FloatingActionButton(
child: const Icon(Icons.refresh),
onPressed: () {
_play(_allDemos[DefaultTabController.of(context)!.index]);
_play(_allDemos[DefaultTabController.of(context).index]);
},
);
},

View File

@@ -172,8 +172,8 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
markers[MarkerType.topLeft] = box!.localToGlobal(Offset.zero);
final Size size = box.size;
markers[MarkerType.bottomRight] = box.localToGlobal(Offset(size.width, size.height));
final ScrollableState? scrollable = Scrollable.of(target.currentContext!);
markersScrollOffset = scrollable!.position.pixels;
final ScrollableState scrollable = Scrollable.of(target.currentContext!);
markersScrollOffset = scrollable.position.pixels;
});
}