diff --git a/packages/flutter/lib/src/cupertino/interface_level.dart b/packages/flutter/lib/src/cupertino/interface_level.dart index e5cd1016f5..a31cb24581 100644 --- a/packages/flutter/lib/src/cupertino/interface_level.dart +++ b/packages/flutter/lib/src/cupertino/interface_level.dart @@ -24,12 +24,14 @@ enum CupertinoUserInterfaceLevelData { /// the given data. /// /// Querying the current elevation status using [CupertinoUserInterfaceLevel.of] -/// will cause your widget to rebuild automatically whenever the [CupertinoUserInterfaceLevelData] -/// changes. +/// will cause your widget to rebuild automatically whenever the +/// [CupertinoUserInterfaceLevelData] changes. /// -/// If no [CupertinoUserInterfaceLevel] is in scope then the [CupertinoUserInterfaceLevel.of] -/// method will throw an exception, unless the `nullOk` argument is set to true, -/// in which case it returns null. +/// If no [CupertinoUserInterfaceLevel] is in scope then the +/// [CupertinoUserInterfaceLevel.of] method will throw an exception. +/// Alternatively, [CupertinoUserInterfaceLevel.maybeOf] can be used, which +/// returns null instead of throwing if no [CupertinoUserInterfaceLevel] is in +/// scope. /// /// See also: /// diff --git a/packages/flutter/lib/src/material/about.dart b/packages/flutter/lib/src/material/about.dart index fd356502c1..dc61cc6de2 100644 --- a/packages/flutter/lib/src/material/about.dart +++ b/packages/flutter/lib/src/material/about.dart @@ -1199,18 +1199,16 @@ class _MasterDetailFlow extends StatefulWidget { /// ```dart /// _MasterDetailFlow.of(context).openDetailPage(arguments); /// ``` - static _MasterDetailFlowProxy? of( - BuildContext context, { - bool nullOk = false, - }) { + static _MasterDetailFlowProxy? of(BuildContext context) { _PageOpener? pageOpener = context.findAncestorStateOfType<_MasterDetailScaffoldState>(); pageOpener ??= context.findAncestorStateOfType<_MasterDetailFlowState>(); assert(() { - if (pageOpener == null && !nullOk) { + if (pageOpener == null) { throw FlutterError( - 'Master Detail operation requested with a context that does not include a Master Detail' - ' Flow.\nThe context used to open a detail page from the Master Detail Flow must be' - ' that of a widget that is a descendant of a Master Detail Flow widget.'); + 'Master Detail operation requested with a context that does not include a Master Detail ' + 'Flow.\nThe context used to open a detail page from the Master Detail Flow must be ' + 'that of a widget that is a descendant of a Master Detail Flow widget.' + ); } return true; }()); diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index 5a731a87a2..12046bc299 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -2796,8 +2796,8 @@ class ScaffoldState extends State with TickerProviderStateMixin, Resto @override void didChangeDependencies() { - // nullOk is valid here since both the Scaffold and ScaffoldMessenger are - // currently available for managing SnackBars. + // Using maybeOf is valid here since both the Scaffold and ScaffoldMessenger + // are currently available for managing SnackBars. final ScaffoldMessengerState? _currentScaffoldMessenger = ScaffoldMessenger.maybeOf(context); // If our ScaffoldMessenger has changed, unregister with the old one first. if (_scaffoldMessenger != null && diff --git a/packages/flutter/lib/src/widgets/media_query.dart b/packages/flutter/lib/src/widgets/media_query.dart index 39fa1c111e..2a5f753764 100644 --- a/packages/flutter/lib/src/widgets/media_query.dart +++ b/packages/flutter/lib/src/widgets/media_query.dart @@ -31,8 +31,8 @@ enum Orientation { /// window, use `MediaQuery.of(context).size`. /// /// If no [MediaQuery] is in scope then the [MediaQuery.of] method will throw an -/// exception, unless the `nullOk` argument is set to true, in which case it -/// returns null. +/// exception. Alternatively, [MediaQuery.maybeOf] may be used, which returns +/// null instead of throwing if no [MediaQuery] is in scope. /// /// ## Insets and Padding /// @@ -629,8 +629,8 @@ class MediaQueryData { /// user rotates their device). /// /// If no [MediaQuery] is in scope then the [MediaQuery.of] method will throw an -/// exception, unless the `nullOk` argument is set to true, in which case it -/// returns null. +/// exception. Alternatively, [MediaQuery.maybeOf] may be used, which returns +/// null instead of throwing if no [MediaQuery] is in scope. /// /// {@youtube 560 315 https://www.youtube.com/watch?v=A3WrA4zAaPw} /// diff --git a/packages/flutter/test/widgets/router_test.dart b/packages/flutter/test/widgets/router_test.dart index f328a433d2..8869030236 100644 --- a/packages/flutter/test/widgets/router_test.dart +++ b/packages/flutter/test/widgets/router_test.dart @@ -88,7 +88,6 @@ void main() { Router? router = Router.maybeOf(textContext); expect(router, isNull); - // Test when the nullOk is not specified. bool hasFlutterError = false; try { router = Router.of(textContext);