Remove nullOk
in MediaQuery.of
(#68736)
Adds MediaQuery.maybeOf to replace calling MediaQuery.of(context, nullOk: true), and removes the nullOk parameter. Also changes MediaQuery.of to return a non-nullable value, and removes many instances of the ! operator, reducing the possible places where a null dereference could occur.
This commit is contained in:
parent
35a94f70e1
commit
55289324c6
@ -71,7 +71,7 @@ class AdaptiveContainer extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (MediaQuery.of(context)!.size.width < _kGridViewBreakpoint) {
|
||||
if (MediaQuery.of(context).size.width < _kGridViewBreakpoint) {
|
||||
return ListView(
|
||||
itemExtent: _kListItemExtent,
|
||||
children: names.map<Widget>((String name) => AdaptedListItem(name: name)).toList(),
|
||||
|
@ -274,12 +274,12 @@ class CupertinoActionSheet extends StatelessWidget {
|
||||
if (cancelButton != null) _buildCancelButton(),
|
||||
];
|
||||
|
||||
final Orientation orientation = MediaQuery.of(context)!.orientation;
|
||||
final Orientation orientation = MediaQuery.of(context).orientation;
|
||||
final double actionSheetWidth;
|
||||
if (orientation == Orientation.portrait) {
|
||||
actionSheetWidth = MediaQuery.of(context)!.size.width - (_kEdgeHorizontalPadding * 2);
|
||||
actionSheetWidth = MediaQuery.of(context).size.width - (_kEdgeHorizontalPadding * 2);
|
||||
} else {
|
||||
actionSheetWidth = MediaQuery.of(context)!.size.height - (_kEdgeHorizontalPadding * 2);
|
||||
actionSheetWidth = MediaQuery.of(context).size.height - (_kEdgeHorizontalPadding * 2);
|
||||
}
|
||||
|
||||
return SafeArea(
|
||||
@ -449,7 +449,7 @@ class _CupertinoAlertRenderWidget extends RenderObjectWidget {
|
||||
RenderObject createRenderObject(BuildContext context) {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
return _RenderCupertinoAlert(
|
||||
dividerThickness: _kDividerThickness / MediaQuery.of(context)!.devicePixelRatio,
|
||||
dividerThickness: _kDividerThickness / MediaQuery.of(context).devicePixelRatio,
|
||||
dividerColor: CupertinoDynamicColor.resolve(_kButtonDividerColor, context)!,
|
||||
);
|
||||
}
|
||||
@ -944,7 +944,7 @@ class _CupertinoAlertActionSection extends StatefulWidget {
|
||||
class _CupertinoAlertActionSectionState extends State<_CupertinoAlertActionSection> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double devicePixelRatio = MediaQuery.of(context)!.devicePixelRatio;
|
||||
final double devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
|
||||
|
||||
final List<Widget> interactiveButtons = <Widget>[];
|
||||
for (int i = 0; i < widget.children.length; i += 1) {
|
||||
|
@ -143,7 +143,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
final double bottomPadding = MediaQuery.of(context)!.padding.bottom;
|
||||
final double bottomPadding = MediaQuery.of(context).padding.bottom;
|
||||
|
||||
final Color? backgroundColor = CupertinoDynamicColor.resolve(
|
||||
this.backgroundColor ?? CupertinoTheme.of(context).barBackgroundColor,
|
||||
|
@ -944,13 +944,18 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
|
||||
/// level), unless [nullOk] is set to false, in which case an exception will be
|
||||
/// thrown.
|
||||
CupertinoDynamicColor resolveFrom(BuildContext context, { bool nullOk = true }) {
|
||||
final Brightness brightness = _isPlatformBrightnessDependent
|
||||
? CupertinoTheme.brightnessOf(context, nullOk: nullOk) ?? Brightness.light
|
||||
: Brightness.light;
|
||||
|
||||
final bool isHighContrastEnabled = _isHighContrastDependent
|
||||
&& (MediaQuery.of(context, nullOk: nullOk)?.highContrast ?? false);
|
||||
|
||||
Brightness brightness = Brightness.light;
|
||||
if (_isPlatformBrightnessDependent) {
|
||||
brightness = nullOk
|
||||
? CupertinoTheme.maybeBrightnessOf(context) ?? Brightness.light
|
||||
: CupertinoTheme.brightnessOf(context);
|
||||
}
|
||||
bool isHighContrastEnabled = false;
|
||||
if (_isHighContrastDependent) {
|
||||
isHighContrastEnabled = nullOk
|
||||
? MediaQuery.maybeOf(context)?.highContrast ?? false
|
||||
: MediaQuery.of(context).highContrast;
|
||||
}
|
||||
|
||||
final CupertinoUserInterfaceLevelData level = _isInterfaceElevationDependent
|
||||
? CupertinoUserInterfaceLevel.of(context, nullOk: nullOk) ?? CupertinoUserInterfaceLevelData.base
|
||||
|
@ -253,7 +253,7 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
|
||||
// it.
|
||||
_ContextMenuLocation get _contextMenuLocation {
|
||||
final Rect childRect = _getRect(_childGlobalKey);
|
||||
final double screenWidth = MediaQuery.of(context)!.size.width;
|
||||
final double screenWidth = MediaQuery.of(context).size.width;
|
||||
|
||||
final double center = screenWidth / 2;
|
||||
final bool centerDividesChild = childRect.left < center
|
||||
@ -1081,7 +1081,7 @@ class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic> with T
|
||||
Widget _buildChildAnimation(BuildContext context, Widget? child) {
|
||||
_lastScale = _getScale(
|
||||
widget.orientation,
|
||||
MediaQuery.of(context)!.size.height,
|
||||
MediaQuery.of(context).size.height,
|
||||
_moveAnimation.value.dy,
|
||||
);
|
||||
return Transform.scale(
|
||||
|
@ -1032,7 +1032,7 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
|
||||
}
|
||||
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 1.0),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
||||
child: DefaultTextStyle.merge(
|
||||
style: _kDefaultPickerTextStyle,
|
||||
child: CustomMultiChildLayout(
|
||||
@ -1403,7 +1403,7 @@ class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
|
||||
}
|
||||
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 1.0),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
||||
child: DefaultTextStyle.merge(
|
||||
style: _kDefaultPickerTextStyle,
|
||||
child: CustomMultiChildLayout(
|
||||
@ -2077,7 +2077,7 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
|
||||
return MediaQuery(
|
||||
// The native iOS picker's text scaling is fixed, so we will also fix it
|
||||
// as well in our picker.
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 1.0),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
||||
child: CupertinoTheme(
|
||||
data: themeData.copyWith(
|
||||
textTheme: themeData.textTheme.copyWith(
|
||||
|
@ -95,7 +95,7 @@ const double _kMaxRegularTextScaleFactor = 1.4;
|
||||
// Accessibility mode on iOS is determined by the text scale factor that the
|
||||
// user has selected.
|
||||
bool _isInAccessibilityMode(BuildContext context) {
|
||||
final MediaQueryData? data = MediaQuery.of(context, nullOk: true);
|
||||
final MediaQueryData? data = MediaQuery.maybeOf(context);
|
||||
return data != null && data.textScaleFactor > _kMaxRegularTextScaleFactor;
|
||||
}
|
||||
|
||||
@ -228,18 +228,18 @@ class CupertinoAlertDialog extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final CupertinoLocalizations localizations = CupertinoLocalizations.of(context);
|
||||
final bool isInAccessibilityMode = _isInAccessibilityMode(context);
|
||||
final double textScaleFactor = MediaQuery.of(context)!.textScaleFactor;
|
||||
final double textScaleFactor = MediaQuery.of(context).textScaleFactor;
|
||||
return CupertinoUserInterfaceLevel(
|
||||
data: CupertinoUserInterfaceLevelData.elevated,
|
||||
child: MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
// iOS does not shrink dialog content below a 1.0 scale factor
|
||||
textScaleFactor: math.max(textScaleFactor, 1.0),
|
||||
),
|
||||
child: LayoutBuilder(
|
||||
builder: (BuildContext context, BoxConstraints constraints) {
|
||||
return AnimatedPadding(
|
||||
padding: MediaQuery.of(context)!.viewInsets +
|
||||
padding: MediaQuery.of(context).viewInsets +
|
||||
const EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0),
|
||||
duration: insetAnimationDuration,
|
||||
curve: insetAnimationCurve,
|
||||
@ -388,7 +388,7 @@ class _CupertinoDialogRenderWidget extends RenderObjectWidget {
|
||||
@override
|
||||
RenderObject createRenderObject(BuildContext context) {
|
||||
return _RenderCupertinoDialog(
|
||||
dividerThickness: _kDividerThickness / MediaQuery.of(context)!.devicePixelRatio,
|
||||
dividerThickness: _kDividerThickness / MediaQuery.of(context).devicePixelRatio,
|
||||
isInAccessibilityMode: _isInAccessibilityMode(context),
|
||||
dividerColor: CupertinoDynamicColor.resolve(CupertinoColors.separator, context)!,
|
||||
);
|
||||
@ -877,7 +877,7 @@ class _CupertinoAlertContentSection extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
final double textScaleFactor = MediaQuery.of(context)!.textScaleFactor;
|
||||
final double textScaleFactor = MediaQuery.of(context).textScaleFactor;
|
||||
final List<Widget> titleContentGroup = <Widget>[
|
||||
if (title != null)
|
||||
Padding(
|
||||
@ -954,7 +954,7 @@ class _CupertinoAlertActionSection extends StatefulWidget {
|
||||
class _CupertinoAlertActionSectionState extends State<_CupertinoAlertActionSection> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double devicePixelRatio = MediaQuery.of(context)!.devicePixelRatio;
|
||||
final double devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
|
||||
|
||||
final List<Widget> interactiveButtons = <Widget>[];
|
||||
for (int i = 0; i < widget.children.length; i += 1) {
|
||||
|
@ -713,7 +713,7 @@ class _CupertinoSliverNavigationBarState extends State<CupertinoSliverNavigation
|
||||
actionsForegroundColor,
|
||||
context,
|
||||
MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 1),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
|
||||
child: SliverPersistentHeader(
|
||||
pinned: true, // iOS navigation bars are always pinned.
|
||||
delegate: _LargeTitleNavigationBarSliverDelegate(
|
||||
@ -727,7 +727,7 @@ class _CupertinoSliverNavigationBarState extends State<CupertinoSliverNavigation
|
||||
actionsForegroundColor: actionsForegroundColor,
|
||||
transitionBetweenRoutes: widget.transitionBetweenRoutes,
|
||||
heroTag: widget.heroTag,
|
||||
persistentHeight: _kNavBarPersistentHeight + MediaQuery.of(context)!.padding.top,
|
||||
persistentHeight: _kNavBarPersistentHeight + MediaQuery.of(context).padding.top,
|
||||
alwaysShowMiddle: widget.middle != null,
|
||||
),
|
||||
),
|
||||
@ -960,7 +960,7 @@ class _PersistentNavigationBar extends StatelessWidget {
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
height: _kNavBarPersistentHeight + MediaQuery.of(context)!.padding.top,
|
||||
height: _kNavBarPersistentHeight + MediaQuery.of(context).padding.top,
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
child: paddedToolbar,
|
||||
@ -1631,7 +1631,7 @@ class _NavigationBarTransition extends StatelessWidget {
|
||||
// can actually be outside the linearly lerp'ed Rect in the middle of
|
||||
// the animation, such as the topLargeTitle.
|
||||
return SizedBox(
|
||||
height: math.max(heightTween.begin!, heightTween.end!) + MediaQuery.of(context)!.padding.top,
|
||||
height: math.max(heightTween.begin!, heightTween.end!) + MediaQuery.of(context).padding.top,
|
||||
width: double.infinity,
|
||||
child: Stack(
|
||||
children: children,
|
||||
|
@ -93,7 +93,7 @@ class _CupertinoPageScaffoldState extends State<CupertinoPageScaffold> {
|
||||
Widget build(BuildContext context) {
|
||||
Widget paddedContent = widget.child;
|
||||
|
||||
final MediaQueryData existingMediaQuery = MediaQuery.of(context)!;
|
||||
final MediaQueryData existingMediaQuery = MediaQuery.of(context);
|
||||
if (widget.navigationBar != null) {
|
||||
// TODO(xster): Use real size after partial layout instead of preferred size.
|
||||
// https://github.com/flutter/flutter/issues/12912
|
||||
|
@ -691,8 +691,8 @@ class _CupertinoBackGestureDetectorState<T> extends State<_CupertinoBackGestureD
|
||||
// For devices with notches, the drag area needs to be larger on the side
|
||||
// that has the notch.
|
||||
double dragAreaWidth = Directionality.of(context) == TextDirection.ltr ?
|
||||
MediaQuery.of(context)!.padding.left :
|
||||
MediaQuery.of(context)!.padding.right;
|
||||
MediaQuery.of(context).padding.left :
|
||||
MediaQuery.of(context).padding.right;
|
||||
dragAreaWidth = max(dragAreaWidth, _kBackGestureWidth);
|
||||
return Stack(
|
||||
fit: StackFit.passthrough,
|
||||
|
@ -285,7 +285,7 @@ class _CupertinoScrollbarState extends State<CupertinoScrollbar> with TickerProv
|
||||
_painter!
|
||||
..textDirection = Directionality.of(context)!
|
||||
..color = CupertinoDynamicColor.resolve(_kScrollbarColor, context)!
|
||||
..padding = MediaQuery.of(context)!.padding;
|
||||
..padding = MediaQuery.of(context).padding;
|
||||
}
|
||||
_triggerScrollbar();
|
||||
}
|
||||
@ -315,7 +315,7 @@ class _CupertinoScrollbarState extends State<CupertinoScrollbar> with TickerProv
|
||||
mainAxisMargin: _kScrollbarMainAxisMargin,
|
||||
crossAxisMargin: _kScrollbarCrossAxisMargin,
|
||||
radius: _radius,
|
||||
padding: MediaQuery.of(context)!.padding,
|
||||
padding: MediaQuery.of(context).padding,
|
||||
minLength: _kScrollbarMinLength,
|
||||
minOverscrollLength: _kScrollbarMinOverscrollLength,
|
||||
);
|
||||
|
@ -388,8 +388,8 @@ class _CupertinoTabScaffoldState extends State<CupertinoTabScaffold> with Restor
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final MediaQueryData existingMediaQuery = MediaQuery.of(context)!;
|
||||
MediaQueryData newMediaQuery = MediaQuery.of(context)!;
|
||||
final MediaQueryData existingMediaQuery = MediaQuery.of(context);
|
||||
MediaQueryData newMediaQuery = MediaQuery.of(context);
|
||||
|
||||
Widget content = _TabSwitchingView(
|
||||
currentTabIndex: _controller.index,
|
||||
|
@ -881,7 +881,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
|
||||
final List<TextInputFormatter> formatters = widget.inputFormatters ?? <TextInputFormatter>[];
|
||||
final TextSelectionControls textSelectionControls = widget.selectionControls ?? cupertinoTextSelectionControls;
|
||||
final bool enabled = widget.enabled ?? true;
|
||||
final Offset cursorOffset = Offset(_iOSHorizontalCursorOffsetPixels / MediaQuery.of(context)!.devicePixelRatio, 0);
|
||||
final Offset cursorOffset = Offset(_iOSHorizontalCursorOffsetPixels / MediaQuery.of(context).devicePixelRatio, 0);
|
||||
if (widget.maxLength != null && widget.maxLengthEnforced) {
|
||||
formatters.add(LengthLimitingTextInputFormatter(widget.maxLength));
|
||||
}
|
||||
@ -901,7 +901,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
|
||||
|
||||
final TextStyle placeholderStyle = textStyle.merge(resolvedPlaceholderStyle);
|
||||
|
||||
final Brightness keyboardAppearance = widget.keyboardAppearance ?? CupertinoTheme.brightnessOf(context)!;
|
||||
final Brightness keyboardAppearance = widget.keyboardAppearance ?? CupertinoTheme.brightnessOf(context);
|
||||
final Color cursorColor = CupertinoDynamicColor.resolve(widget.cursorColor, context) ?? themeData.primaryColor;
|
||||
final Color? disabledColor = CupertinoDynamicColor.resolve(_kDisabledBackground, context);
|
||||
|
||||
|
@ -157,7 +157,7 @@ class _CupertinoTextSelectionToolbarWrapperState extends State<_CupertinoTextSel
|
||||
? EdgeInsets.only(bottom: _kToolbarArrowSize.height)
|
||||
: EdgeInsets.only(top: _kToolbarArrowSize.height);
|
||||
final Widget onePhysicalPixelVerticalDivider =
|
||||
SizedBox(width: 1.0 / MediaQuery.of(context)!.devicePixelRatio);
|
||||
SizedBox(width: 1.0 / MediaQuery.of(context).devicePixelRatio);
|
||||
|
||||
void addToolbarButton(
|
||||
String text,
|
||||
@ -463,7 +463,7 @@ class _CupertinoTextSelectionControls extends TextSelectionControls {
|
||||
ClipboardStatusNotifier clipboardStatus,
|
||||
) {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context)!;
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
|
||||
// The toolbar should appear below the TextField when there is not enough
|
||||
// space above the TextField to show it, assuming there's always enough space
|
||||
@ -664,7 +664,7 @@ class _CupertinoTextSelectionToolbarContentState extends State<_CupertinoTextSel
|
||||
pressedOpacity: 0.7,
|
||||
child: const Text('◀', style: _kToolbarButtonFontStyle),
|
||||
),
|
||||
dividerWidth: 1.0 / MediaQuery.of(context)!.devicePixelRatio,
|
||||
dividerWidth: 1.0 / MediaQuery.of(context).devicePixelRatio,
|
||||
nextButton: CupertinoButton(
|
||||
borderRadius: null,
|
||||
color: _kToolbarBackgroundColor,
|
||||
|
@ -78,15 +78,37 @@ class CupertinoTheme extends StatelessWidget {
|
||||
/// is null, it will fall back to [MediaQueryData.platformBrightness].
|
||||
///
|
||||
/// Throws an exception if no valid [CupertinoTheme] or [MediaQuery] widgets
|
||||
/// exist in the ancestry tree, unless [nullOk] is set to true.
|
||||
/// exist in the ancestry tree.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [maybeBrightnessOf], which returns null if no valid [CupertinoTheme] or
|
||||
/// [MediaQuery] exists, instead of throwing.
|
||||
/// * [CupertinoThemeData.brightness], the property takes precedence over
|
||||
/// [MediaQueryData.platformBrightness] for descendant Cupertino widgets.
|
||||
static Brightness brightnessOf(BuildContext context) {
|
||||
final _InheritedCupertinoTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>();
|
||||
return inheritedTheme?.theme.data.brightness ?? MediaQuery.of(context).platformBrightness;
|
||||
}
|
||||
|
||||
/// Retrieves the [Brightness] to use for descendant Cupertino widgets, based
|
||||
/// on the value of [CupertinoThemeData.brightness] in the given [context].
|
||||
///
|
||||
/// If no [CupertinoTheme] can be found in the given [context], it will fall
|
||||
/// back to [MediaQueryData.platformBrightness].
|
||||
///
|
||||
/// Returns null if no valid [CupertinoTheme] or [MediaQuery] widgets exist in
|
||||
/// the ancestry tree.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [CupertinoThemeData.brightness], the property takes precedence over
|
||||
/// [MediaQueryData.platformBrightness] for descendant Cupertino widgets.
|
||||
static Brightness? brightnessOf(BuildContext context, { bool nullOk = false }) {
|
||||
/// * [brightnessOf], which throws if no valid [CupertinoTheme] or
|
||||
/// [MediaQuery] exists, instead of returning null.
|
||||
static Brightness? maybeBrightnessOf(BuildContext context) {
|
||||
final _InheritedCupertinoTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>();
|
||||
return inheritedTheme?.theme.data.brightness ?? MediaQuery.of(context, nullOk: nullOk)?.platformBrightness;
|
||||
return inheritedTheme?.theme.data.brightness ?? MediaQuery.maybeOf(context)?.platformBrightness;
|
||||
}
|
||||
|
||||
/// The widget below this widget in the tree.
|
||||
|
@ -1018,7 +1018,7 @@ const double _wideGutterSize = 24.0;
|
||||
const double _narrowGutterSize = 12.0;
|
||||
|
||||
double _getGutterSize(BuildContext context) =>
|
||||
MediaQuery.of(context)!.size.width >= _materialGutterThreshold ? _wideGutterSize : _narrowGutterSize;
|
||||
MediaQuery.of(context).size.width >= _materialGutterThreshold ? _wideGutterSize : _narrowGutterSize;
|
||||
|
||||
/// Signature for the builder callback used by [_MasterDetailFlow].
|
||||
typedef _MasterViewBuilder = Widget Function(BuildContext context, bool isLateralUI);
|
||||
@ -1627,7 +1627,7 @@ class _DetailView extends StatelessWidget {
|
||||
if (_arguments == null) {
|
||||
return Container();
|
||||
}
|
||||
final double screenHeight = MediaQuery.of(context)!.size.height;
|
||||
final double screenHeight = MediaQuery.of(context).size.height;
|
||||
final double minHeight = (screenHeight - kToolbarHeight) / screenHeight;
|
||||
|
||||
return DraggableScrollableSheet(
|
||||
|
@ -593,7 +593,7 @@ class _AppBarState extends State<AppBar> {
|
||||
// sizes. To opt out, wrap the [title] widget in a [MediaQuery] widget
|
||||
// with [MediaQueryData.textScaleFactor] set to
|
||||
// `MediaQuery.textScaleFactorOf(context)`.
|
||||
final MediaQueryData mediaQueryData = MediaQuery.of(context)!;
|
||||
final MediaQueryData mediaQueryData = MediaQuery.of(context);
|
||||
title = MediaQuery(
|
||||
data: mediaQueryData.copyWith(
|
||||
textScaleFactor: math.min(
|
||||
@ -1447,7 +1447,7 @@ class _SliverAppBarState extends State<SliverAppBar> with TickerProviderStateMix
|
||||
Widget build(BuildContext context) {
|
||||
assert(!widget.primary || debugCheckHasMediaQuery(context));
|
||||
final double bottomHeight = widget.bottom?.preferredSize.height ?? 0.0;
|
||||
final double topPadding = widget.primary ? MediaQuery.of(context)!.padding.top : 0.0;
|
||||
final double topPadding = widget.primary ? MediaQuery.of(context).padding.top : 0.0;
|
||||
final double collapsedHeight = (widget.pinned && widget.floating && widget.bottom != null)
|
||||
? (widget.collapsedHeight ?? 0.0) + bottomHeight + topPadding
|
||||
: (widget.collapsedHeight ?? widget.toolbarHeight) + bottomHeight + topPadding;
|
||||
|
@ -657,7 +657,7 @@ class _Label extends StatelessWidget {
|
||||
if (item.label != null) {
|
||||
// Do not grow text in bottom navigation bar when we can show a tooltip
|
||||
// instead.
|
||||
final MediaQueryData mediaQueryData = MediaQuery.of(context)!;
|
||||
final MediaQueryData mediaQueryData = MediaQuery.of(context);
|
||||
text = MediaQuery(
|
||||
data: mediaQueryData.copyWith(
|
||||
textScaleFactor: math.min(1.0, mediaQueryData.textScaleFactor),
|
||||
@ -920,7 +920,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
|
||||
final BottomNavigationBarThemeData bottomTheme = BottomNavigationBarTheme.of(context);
|
||||
|
||||
// Labels apply up to _bottomMargin padding. Remainder is media padding.
|
||||
final double additionalBottomPadding = math.max(MediaQuery.of(context)!.padding.bottom - widget.selectedFontSize / 2.0, 0.0);
|
||||
final double additionalBottomPadding = math.max(MediaQuery.of(context).padding.bottom - widget.selectedFontSize / 2.0, 0.0);
|
||||
Color? backgroundColor;
|
||||
switch (_effectiveType) {
|
||||
case BottomNavigationBarType.fixed:
|
||||
|
@ -369,7 +369,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
assert(debugCheckHasMaterialLocalizations(context));
|
||||
final MediaQueryData? mediaQuery = MediaQuery.of(context);
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
final String routeLabel = _getRouteLabel(localizations);
|
||||
|
||||
@ -395,7 +395,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
|
||||
// Disable the initial animation when accessible navigation is on so
|
||||
// that the semantics are added to the tree at the correct time.
|
||||
final double animationValue = animationCurve.transform(
|
||||
mediaQuery!.accessibleNavigation ? 1.0 : widget.route!.animation!.value
|
||||
mediaQuery.accessibleNavigation ? 1.0 : widget.route!.animation!.value
|
||||
);
|
||||
return Semantics(
|
||||
scopesRoute: true,
|
||||
|
@ -1829,7 +1829,7 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
|
||||
final EdgeInsetsGeometry _defaultLabelPadding = EdgeInsets.lerp(
|
||||
const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
const EdgeInsets.symmetric(horizontal: 4.0),
|
||||
(MediaQuery.of(context)!.textScaleFactor - 1.0).clamp(0.0, 1.0),
|
||||
(MediaQuery.of(context).textScaleFactor - 1.0).clamp(0.0, 1.0),
|
||||
)!;
|
||||
|
||||
final ThemeData theme = Theme.of(context)!;
|
||||
|
@ -223,7 +223,7 @@ class CircleAvatar extends StatelessWidget {
|
||||
child: MediaQuery(
|
||||
// Need to ignore the ambient textScaleFactor here so that the
|
||||
// text doesn't escape the avatar when the textScaleFactor is large.
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 1.0),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
||||
child: IconTheme(
|
||||
data: theme.iconTheme.copyWith(color: textStyle.color),
|
||||
child: DefaultTextStyle(
|
||||
|
@ -128,7 +128,7 @@ class Dialog extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final DialogTheme dialogTheme = DialogTheme.of(context);
|
||||
final EdgeInsets effectivePadding = MediaQuery.of(context)!.viewInsets + (insetPadding ?? const EdgeInsets.all(0.0));
|
||||
final EdgeInsets effectivePadding = MediaQuery.of(context).viewInsets + (insetPadding ?? const EdgeInsets.all(0.0));
|
||||
return AnimatedPadding(
|
||||
padding: effectivePadding,
|
||||
duration: insetAnimationDuration,
|
||||
@ -468,7 +468,7 @@ class AlertDialog extends StatelessWidget {
|
||||
|
||||
// The paddingScaleFactor is used to adjust the padding of Dialog's
|
||||
// children.
|
||||
final double paddingScaleFactor = _paddingScaleFactor(MediaQuery.of(context)!.textScaleFactor);
|
||||
final double paddingScaleFactor = _paddingScaleFactor(MediaQuery.of(context).textScaleFactor);
|
||||
final TextDirection? textDirection = Directionality.maybeOf(context);
|
||||
|
||||
Widget? titleWidget;
|
||||
@ -825,7 +825,7 @@ class SimpleDialog extends StatelessWidget {
|
||||
|
||||
// The paddingScaleFactor is used to adjust the padding of Dialog
|
||||
// children.
|
||||
final double paddingScaleFactor = _paddingScaleFactor(MediaQuery.of(context)!.textScaleFactor);
|
||||
final double paddingScaleFactor = _paddingScaleFactor(MediaQuery.of(context).textScaleFactor);
|
||||
final TextDirection? textDirection = Directionality.maybeOf(context);
|
||||
|
||||
Widget? titleWidget;
|
||||
|
@ -498,7 +498,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
|
||||
|
||||
Widget _buildDrawer(BuildContext context) {
|
||||
final bool drawerIsStart = widget.alignment == DrawerAlignment.start;
|
||||
final EdgeInsets padding = MediaQuery.of(context)!.padding;
|
||||
final EdgeInsets padding = MediaQuery.of(context).padding;
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
|
||||
double? dragAreaWidth = widget.edgeDragWidth;
|
||||
|
@ -76,7 +76,7 @@ class DrawerHeader extends StatelessWidget {
|
||||
assert(debugCheckHasMaterial(context));
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
final ThemeData? theme = Theme.of(context);
|
||||
final double statusBarHeight = MediaQuery.of(context)!.padding.top;
|
||||
final double statusBarHeight = MediaQuery.of(context).padding.top;
|
||||
return Container(
|
||||
height: statusBarHeight + _kDrawerHeaderHeight,
|
||||
margin: margin,
|
||||
|
@ -1269,7 +1269,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
|
||||
bool get _enabled => widget.items != null && widget.items!.isNotEmpty && widget.onChanged != null;
|
||||
|
||||
Orientation _getOrientation(BuildContext context) {
|
||||
Orientation? result = MediaQuery.of(context, nullOk: true)?.orientation;
|
||||
Orientation? result = MediaQuery.maybeOf(context)?.orientation;
|
||||
if (result == null) {
|
||||
// If there's no MediaQuery, then use the window aspect to determine
|
||||
// orientation.
|
||||
|
@ -255,7 +255,7 @@ class ElevatedButton extends ButtonStyleButton {
|
||||
const EdgeInsets.symmetric(horizontal: 16),
|
||||
const EdgeInsets.symmetric(horizontal: 8),
|
||||
const EdgeInsets.symmetric(horizontal: 4),
|
||||
MediaQuery.of(context, nullOk: true)?.textScaleFactor ?? 1,
|
||||
MediaQuery.maybeOf(context)?.textScaleFactor ?? 1,
|
||||
);
|
||||
|
||||
return styleFrom(
|
||||
@ -397,7 +397,7 @@ class _ElevatedButtonWithIcon extends ElevatedButton {
|
||||
const EdgeInsetsDirectional.fromSTEB(12, 0, 16, 0),
|
||||
const EdgeInsets.symmetric(horizontal: 8),
|
||||
const EdgeInsetsDirectional.fromSTEB(8, 0, 4, 0),
|
||||
MediaQuery.of(context, nullOk: true)?.textScaleFactor ?? 1,
|
||||
MediaQuery.maybeOf(context)?.textScaleFactor ?? 1,
|
||||
);
|
||||
return super.defaultStyleOf(context).copyWith(
|
||||
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(scaledPadding)
|
||||
@ -413,7 +413,7 @@ class _ElevatedButtonWithIconChild extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double scale = MediaQuery.of(context, nullOk: true)?.textScaleFactor ?? 1;
|
||||
final double scale = MediaQuery.maybeOf(context)?.textScaleFactor ?? 1;
|
||||
final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!;
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
@ -916,7 +916,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
|
||||
}
|
||||
|
||||
bool get _shouldShowFocus {
|
||||
final NavigationMode mode = MediaQuery.of(context, nullOk: true)?.navigationMode ?? NavigationMode.traditional;
|
||||
final NavigationMode mode = MediaQuery.maybeOf(context)?.navigationMode ?? NavigationMode.traditional;
|
||||
switch (mode) {
|
||||
case NavigationMode.traditional:
|
||||
return enabled && _hasFocus;
|
||||
@ -1055,7 +1055,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
|
||||
}
|
||||
|
||||
bool get _canRequestFocus {
|
||||
final NavigationMode mode = MediaQuery.of(context, nullOk: true)?.navigationMode ?? NavigationMode.traditional;
|
||||
final NavigationMode mode = MediaQuery.maybeOf(context)?.navigationMode ?? NavigationMode.traditional;
|
||||
switch (mode) {
|
||||
case NavigationMode.traditional:
|
||||
return enabled && widget.canRequestFocus;
|
||||
|
@ -226,7 +226,7 @@ class OutlinedButton extends ButtonStyleButton {
|
||||
const EdgeInsets.symmetric(horizontal: 16),
|
||||
const EdgeInsets.symmetric(horizontal: 8),
|
||||
const EdgeInsets.symmetric(horizontal: 4),
|
||||
MediaQuery.of(context, nullOk: true)?.textScaleFactor ?? 1,
|
||||
MediaQuery.maybeOf(context)?.textScaleFactor ?? 1,
|
||||
);
|
||||
|
||||
return styleFrom(
|
||||
@ -341,7 +341,7 @@ class _OutlinedButtonWithIconChild extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double scale = MediaQuery.of(context, nullOk: true)?.textScaleFactor ?? 1;
|
||||
final double scale = MediaQuery.maybeOf(context)?.textScaleFactor ?? 1;
|
||||
final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!;
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
@ -436,7 +436,7 @@ class _DayHeaders extends StatelessWidget {
|
||||
|
||||
return Container(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: MediaQuery.of(context)!.orientation == Orientation.landscape
|
||||
maxWidth: MediaQuery.of(context).orientation == Orientation.landscape
|
||||
? _maxCalendarWidthLandscape
|
||||
: _maxCalendarWidthPortrait,
|
||||
maxHeight: _monthItemRowHeight,
|
||||
@ -888,7 +888,7 @@ class _MonthItemState extends State<_MonthItem> {
|
||||
paddedDayItems.addAll(weekList);
|
||||
}
|
||||
|
||||
final double maxWidth = MediaQuery.of(context)!.orientation == Orientation.landscape
|
||||
final double maxWidth = MediaQuery.of(context).orientation == Orientation.landscape
|
||||
? _maxCalendarWidthLandscape
|
||||
: _maxCalendarWidthPortrait;
|
||||
return Column(
|
||||
|
@ -331,7 +331,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
|
||||
}
|
||||
|
||||
Size _dialogSize(BuildContext context) {
|
||||
final Orientation orientation = MediaQuery.of(context)!.orientation;
|
||||
final Orientation orientation = MediaQuery.of(context).orientation;
|
||||
switch (_entryMode) {
|
||||
case DatePickerEntryMode.calendar:
|
||||
switch (orientation) {
|
||||
@ -360,11 +360,11 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
|
||||
final ThemeData theme = Theme.of(context)!;
|
||||
final ColorScheme colorScheme = theme.colorScheme;
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
final Orientation orientation = MediaQuery.of(context)!.orientation;
|
||||
final Orientation orientation = MediaQuery.of(context).orientation;
|
||||
final TextTheme textTheme = theme.textTheme;
|
||||
// Constrain the textScaleFactor to the largest supported value to prevent
|
||||
// layout issues.
|
||||
final double textScaleFactor = math.min(MediaQuery.of(context)!.textScaleFactor, 1.3);
|
||||
final double textScaleFactor = math.min(MediaQuery.of(context).textScaleFactor, 1.3);
|
||||
|
||||
final String dateText = localizations.formatMediumDate(_selectedDate);
|
||||
final Color dateColor = colorScheme.brightness == Brightness.light
|
||||
@ -467,7 +467,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
|
||||
duration: _dialogSizeAnimationDuration,
|
||||
curve: Curves.easeIn,
|
||||
child: MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
textScaleFactor: textScaleFactor,
|
||||
),
|
||||
child: Builder(builder: (BuildContext context) {
|
||||
|
@ -335,7 +335,7 @@ class _DateRangePickerDialogState extends State<_DateRangePickerDialog> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context)!;
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
final Orientation orientation = mediaQuery.orientation;
|
||||
final double textScaleFactor = math.min(mediaQuery.textScaleFactor, 1.3);
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
@ -428,7 +428,7 @@ class _DateRangePickerDialogState extends State<_DateRangePickerDialog> {
|
||||
duration: _dialogSizeAnimationDuration,
|
||||
curve: Curves.easeIn,
|
||||
child: MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
textScaleFactor: textScaleFactor,
|
||||
),
|
||||
child: Builder(builder: (BuildContext context) {
|
||||
@ -479,7 +479,7 @@ class _CalendarRangePickerDialog extends StatelessWidget {
|
||||
final ThemeData theme = Theme.of(context)!;
|
||||
final ColorScheme colorScheme = theme.colorScheme;
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
final Orientation orientation = MediaQuery.of(context)!.orientation;
|
||||
final Orientation orientation = MediaQuery.of(context).orientation;
|
||||
final TextTheme textTheme = theme.textTheme;
|
||||
final Color headerForeground = colorScheme.brightness == Brightness.light
|
||||
? colorScheme.onPrimary
|
||||
@ -525,7 +525,7 @@ class _CalendarRangePickerDialog extends StatelessWidget {
|
||||
],
|
||||
bottom: PreferredSize(
|
||||
child: Row(children: <Widget>[
|
||||
SizedBox(width: MediaQuery.of(context)!.size.width < 360 ? 42 : 72),
|
||||
SizedBox(width: MediaQuery.of(context).size.width < 360 ? 42 : 72),
|
||||
Expanded(
|
||||
child: Semantics(
|
||||
label: '$helpText $startDateText to $endDateText',
|
||||
@ -633,7 +633,7 @@ class _InputDateRangePickerDialog extends StatelessWidget {
|
||||
final ThemeData theme = Theme.of(context)!;
|
||||
final ColorScheme colorScheme = theme.colorScheme;
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
final Orientation orientation = MediaQuery.of(context)!.orientation;
|
||||
final Orientation orientation = MediaQuery.of(context).orientation;
|
||||
final TextTheme textTheme = theme.textTheme;
|
||||
|
||||
final Color dateColor = colorScheme.brightness == Brightness.light
|
||||
|
@ -1098,7 +1098,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
|
||||
}
|
||||
|
||||
bool get _canRequestFocus {
|
||||
final NavigationMode mode = MediaQuery.of(context, nullOk: true)?.navigationMode ?? NavigationMode.traditional;
|
||||
final NavigationMode mode = MediaQuery.maybeOf(context)?.navigationMode ?? NavigationMode.traditional;
|
||||
switch (mode) {
|
||||
case NavigationMode.traditional:
|
||||
return widget.enabled;
|
||||
|
@ -637,7 +637,7 @@ class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin
|
||||
// This size is used as the max bounds for the painting of the value
|
||||
// indicators. It must be kept in sync with the function with the same name
|
||||
// in slider.dart.
|
||||
Size _screenSize() => MediaQuery.of(context)!.size;
|
||||
Size _screenSize() => MediaQuery.of(context).size;
|
||||
|
||||
return CompositedTransformTarget(
|
||||
link: _layerLink,
|
||||
@ -646,7 +646,7 @@ class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin
|
||||
divisions: widget.divisions,
|
||||
labels: widget.labels,
|
||||
sliderTheme: sliderTheme,
|
||||
textScaleFactor: MediaQuery.of(context)!.textScaleFactor,
|
||||
textScaleFactor: MediaQuery.of(context).textScaleFactor,
|
||||
screenSize: _screenSize(),
|
||||
onChanged: (widget.onChanged != null) && (widget.max > widget.min) ? _handleChanged : null,
|
||||
onChangeStart: widget.onChangeStart != null ? _handleDragStart : null,
|
||||
|
@ -240,7 +240,7 @@ class ScaffoldMessengerState extends State<ScaffoldMessenger> with TickerProvide
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context)!;
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
// If we transition from accessible navigation to non-accessible navigation
|
||||
// and there is a SnackBar that would have timed out that has already
|
||||
// completed its timer, dismiss that SnackBar. If the timer hasn't finished
|
||||
@ -406,7 +406,7 @@ class ScaffoldMessengerState extends State<ScaffoldMessenger> with TickerProvide
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context)!;
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
_accessibleNavigation = mediaQuery.accessibleNavigation;
|
||||
|
||||
if (_snackBars.isNotEmpty) {
|
||||
@ -418,7 +418,7 @@ class ScaffoldMessengerState extends State<ScaffoldMessenger> with TickerProvide
|
||||
assert(_snackBarController!.status == AnimationStatus.forward ||
|
||||
_snackBarController!.status == AnimationStatus.completed);
|
||||
// Look up MediaQuery again in case the setting changed.
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context)!;
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
if (mediaQuery.accessibleNavigation && snackBar.action != null)
|
||||
return;
|
||||
hideCurrentSnackBar(reason: SnackBarClosedReason.timeout);
|
||||
@ -769,7 +769,7 @@ class _BodyBuilder extends StatelessWidget {
|
||||
return LayoutBuilder(
|
||||
builder: (BuildContext context, BoxConstraints constraints) {
|
||||
final _BodyBoxConstraints bodyConstraints = constraints as _BodyBoxConstraints;
|
||||
final MediaQueryData metrics = MediaQuery.of(context)!;
|
||||
final MediaQueryData metrics = MediaQuery.of(context);
|
||||
|
||||
final double bottom = extendBody
|
||||
? math.max(metrics.padding.bottom, bodyConstraints.bottomWidgetsHeight)
|
||||
@ -2281,7 +2281,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
|
||||
|
||||
if (_snackBars.isEmpty || _snackBarController!.status == AnimationStatus.dismissed)
|
||||
return;
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context)!;
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
final Completer<SnackBarClosedReason> completer = _snackBars.first._completer;
|
||||
if (mediaQuery.accessibleNavigation) {
|
||||
_snackBarController!.value = 0.0;
|
||||
@ -2725,7 +2725,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
|
||||
_scaffoldMessenger?._register(this);
|
||||
|
||||
// TODO(Piinks): Remove old SnackBar API after migrating ScaffoldMessenger
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context)!;
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
// If we transition from accessible navigation to non-accessible navigation
|
||||
// and there is a SnackBar that would have timed out that has already
|
||||
// completed its timer, dismiss that SnackBar. If the timer hasn't finished
|
||||
@ -2773,7 +2773,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
|
||||
bool removeBottomInset = false,
|
||||
bool maintainBottomViewPadding = false,
|
||||
}) {
|
||||
MediaQueryData data = MediaQuery.of(context)!.removePadding(
|
||||
MediaQueryData data = MediaQuery.of(context).removePadding(
|
||||
removeLeft: removeLeftPadding,
|
||||
removeTop: removeTopPadding,
|
||||
removeRight: removeRightPadding,
|
||||
@ -2869,7 +2869,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
assert(debugCheckHasDirectionality(context));
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context)!;
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
final ThemeData themeData = Theme.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
|
||||
@ -2884,7 +2884,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
|
||||
assert(_snackBarController!.status == AnimationStatus.forward ||
|
||||
_snackBarController!.status == AnimationStatus.completed);
|
||||
// Look up MediaQuery again in case the setting changed.
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context)!;
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
if (mediaQuery.accessibleNavigation && snackBar.action != null)
|
||||
return;
|
||||
hideCurrentSnackBar(reason: SnackBarClosedReason.timeout);
|
||||
|
@ -167,7 +167,7 @@ class _ScrollbarState extends State<Scrollbar> with SingleTickerProviderStateMix
|
||||
thickness: widget.thickness ?? _kScrollbarThickness,
|
||||
radius: widget.radius,
|
||||
fadeoutOpacityAnimation: _fadeoutOpacityAnimation,
|
||||
padding: MediaQuery.of(context)!.padding,
|
||||
padding: MediaQuery.of(context).padding,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -590,7 +590,7 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
|
||||
cursorColor ??= selectionTheme.cursorColor ?? cupertinoTheme.primaryColor;
|
||||
selectionColor = selectionTheme.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40);
|
||||
cursorRadius ??= const Radius.circular(2.0);
|
||||
cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.of(context)!.devicePixelRatio, 0);
|
||||
cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.of(context).devicePixelRatio, 0);
|
||||
break;
|
||||
|
||||
case TargetPlatform.android:
|
||||
|
@ -703,7 +703,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
|
||||
// This size is used as the max bounds for the painting of the value
|
||||
// indicators It must be kept in sync with the function with the same name
|
||||
// in range_slider.dart.
|
||||
Size _screenSize() => MediaQuery.of(context)!.size;
|
||||
Size _screenSize() => MediaQuery.of(context).size;
|
||||
|
||||
return Semantics(
|
||||
container: true,
|
||||
@ -725,7 +725,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
|
||||
divisions: widget.divisions,
|
||||
label: widget.label,
|
||||
sliderTheme: sliderTheme,
|
||||
textScaleFactor: MediaQuery.of(context)!.textScaleFactor,
|
||||
textScaleFactor: MediaQuery.of(context).textScaleFactor,
|
||||
screenSize: _screenSize(),
|
||||
onChanged: (widget.onChanged != null) && (widget.max > widget.min) ? _handleChanged : null,
|
||||
onChangeStart: widget.onChangeStart != null ? _handleDragStart : null,
|
||||
|
@ -383,7 +383,7 @@ class _SnackBarState extends State<SnackBar> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
final MediaQueryData mediaQueryData = MediaQuery.of(context)!;
|
||||
final MediaQueryData mediaQueryData = MediaQuery.of(context);
|
||||
assert(widget.animation != null);
|
||||
final ThemeData theme = Theme.of(context)!;
|
||||
final ColorScheme colorScheme = theme.colorScheme;
|
||||
|
@ -242,7 +242,7 @@ class TextButton extends ButtonStyleButton {
|
||||
const EdgeInsets.all(8),
|
||||
const EdgeInsets.symmetric(horizontal: 8),
|
||||
const EdgeInsets.symmetric(horizontal: 4),
|
||||
MediaQuery.of(context, nullOk: true)?.textScaleFactor ?? 1,
|
||||
MediaQuery.maybeOf(context)?.textScaleFactor ?? 1,
|
||||
);
|
||||
|
||||
return styleFrom(
|
||||
@ -359,7 +359,7 @@ class _TextButtonWithIcon extends TextButton {
|
||||
const EdgeInsets.all(8),
|
||||
const EdgeInsets.symmetric(horizontal: 4),
|
||||
const EdgeInsets.symmetric(horizontal: 4),
|
||||
MediaQuery.of(context, nullOk: true)?.textScaleFactor ?? 1,
|
||||
MediaQuery.maybeOf(context)?.textScaleFactor ?? 1,
|
||||
);
|
||||
return super.defaultStyleOf(context).copyWith(
|
||||
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(scaledPadding)
|
||||
@ -379,7 +379,7 @@ class _TextButtonWithIconChild extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double scale = MediaQuery.of(context, nullOk: true)?.textScaleFactor ?? 1;
|
||||
final double scale = MediaQuery.maybeOf(context)?.textScaleFactor ?? 1;
|
||||
final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!;
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
@ -1059,7 +1059,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
||||
}
|
||||
|
||||
bool get _canRequestFocus {
|
||||
final NavigationMode mode = MediaQuery.of(context, nullOk: true)?.navigationMode ?? NavigationMode.traditional;
|
||||
final NavigationMode mode = MediaQuery.maybeOf(context)?.navigationMode ?? NavigationMode.traditional;
|
||||
switch (mode) {
|
||||
case NavigationMode.traditional:
|
||||
return _isEnabled;
|
||||
@ -1285,7 +1285,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
||||
cursorColor ??= selectionTheme.cursorColor ?? cupertinoTheme.primaryColor;
|
||||
selectionColor = selectionTheme.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40);
|
||||
cursorRadius ??= const Radius.circular(2.0);
|
||||
cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.of(context)!.devicePixelRatio, 0);
|
||||
cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.of(context).devicePixelRatio, 0);
|
||||
autocorrectionTextRectColor = selectionColor;
|
||||
break;
|
||||
|
||||
|
@ -760,7 +760,7 @@ class _MaterialTextSelectionControls extends TextSelectionControls {
|
||||
const double closedToolbarHeightNeeded = _kToolbarScreenPadding
|
||||
+ _kToolbarHeight
|
||||
+ _kToolbarContentDistance;
|
||||
final double paddingTop = MediaQuery.of(context)!.padding.top;
|
||||
final double paddingTop = MediaQuery.of(context).padding.top;
|
||||
final double availableHeight = globalEditableRegion.top
|
||||
+ startTextSelectionPoint.point.dy
|
||||
- textLineHeight
|
||||
|
@ -107,7 +107,7 @@ class TimeOfDay {
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
return localizations.formatTimeOfDay(
|
||||
this,
|
||||
alwaysUse24HourFormat: MediaQuery.of(context)!.alwaysUse24HourFormat,
|
||||
alwaysUse24HourFormat: MediaQuery.of(context).alwaysUse24HourFormat,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ class _TimePickerHeader extends StatelessWidget {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
final ThemeData themeData = Theme.of(context)!;
|
||||
final TimeOfDayFormat timeOfDayFormat = MaterialLocalizations.of(context).timeOfDayFormat(
|
||||
alwaysUse24HourFormat: MediaQuery.of(context)!.alwaysUse24HourFormat,
|
||||
alwaysUse24HourFormat: MediaQuery.of(context).alwaysUse24HourFormat,
|
||||
);
|
||||
|
||||
final _TimePickerFragmentContext fragmentContext = _TimePickerFragmentContext(
|
||||
@ -321,7 +321,7 @@ class _HourControl extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
final bool alwaysUse24HourFormat = MediaQuery.of(context)!.alwaysUse24HourFormat;
|
||||
final bool alwaysUse24HourFormat = MediaQuery.of(context).alwaysUse24HourFormat;
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
final String formattedHour = localizations.formatHour(
|
||||
fragmentContext.selectedTime,
|
||||
@ -563,7 +563,7 @@ class _DayPeriodControl extends StatelessWidget {
|
||||
side: borderSide,
|
||||
);
|
||||
|
||||
final double buttonTextScaleFactor = math.min(MediaQuery.of(context)!.textScaleFactor, 2.0);
|
||||
final double buttonTextScaleFactor = math.min(MediaQuery.of(context).textScaleFactor, 2.0);
|
||||
|
||||
final Widget amButton = Material(
|
||||
color: MaterialStateProperty.resolveAs(backgroundColor, amStates),
|
||||
@ -942,7 +942,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
themeData = Theme.of(context)!;
|
||||
localizations = MaterialLocalizations.of(context);
|
||||
media = MediaQuery.of(context)!;
|
||||
media = MediaQuery.of(context);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -1152,7 +1152,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
|
||||
|
||||
_TappableLabel _buildTappableLabel(TextTheme textTheme, Color color, int value, String label, VoidCallback onTap) {
|
||||
final TextStyle style = textTheme.bodyText1!.copyWith(color: color);
|
||||
final double labelScaleFactor = math.min(MediaQuery.of(context)!.textScaleFactor, 2.0);
|
||||
final double labelScaleFactor = math.min(MediaQuery.of(context).textScaleFactor, 2.0);
|
||||
return _TappableLabel(
|
||||
value: value,
|
||||
painter: TextPainter(
|
||||
@ -1322,7 +1322,7 @@ class _TimePickerInputState extends State<_TimePickerInput> {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (MediaQuery.of(context)!.alwaysUse24HourFormat) {
|
||||
if (MediaQuery.of(context).alwaysUse24HourFormat) {
|
||||
if (newHour >= 0 && newHour < 24) {
|
||||
return newHour;
|
||||
}
|
||||
@ -1408,7 +1408,7 @@ class _TimePickerInputState extends State<_TimePickerInput> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
final MediaQueryData media = MediaQuery.of(context)!;
|
||||
final MediaQueryData media = MediaQuery.of(context);
|
||||
final TimeOfDayFormat timeOfDayFormat = MaterialLocalizations.of(context).timeOfDayFormat(alwaysUse24HourFormat: media.alwaysUse24HourFormat);
|
||||
final bool use24HourDials = hourFormat(of: timeOfDayFormat) != HourFormat.h;
|
||||
final ThemeData theme = Theme.of(context)!;
|
||||
@ -1631,7 +1631,7 @@ class _HourMinuteTextFieldState extends State<_HourMinuteTextField> {
|
||||
}
|
||||
|
||||
String get _formattedValue {
|
||||
final bool alwaysUse24HourFormat = MediaQuery.of(context)!.alwaysUse24HourFormat;
|
||||
final bool alwaysUse24HourFormat = MediaQuery.of(context).alwaysUse24HourFormat;
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
return !widget.isHour ? localizations.formatMinute(widget.selectedTime) : localizations.formatHour(
|
||||
widget.selectedTime,
|
||||
@ -1677,7 +1677,7 @@ class _HourMinuteTextFieldState extends State<_HourMinuteTextField> {
|
||||
//
|
||||
// TODO(rami-a): Once https://github.com/flutter/flutter/issues/67571 is
|
||||
// resolved, remove the window check for semantics being enabled on web.
|
||||
final String? hintText = MediaQuery.of(context)!.accessibleNavigation || ui.window.semanticsEnabled
|
||||
final String? hintText = MediaQuery.of(context).accessibleNavigation || ui.window.semanticsEnabled
|
||||
? widget.semanticHintText
|
||||
: (focusNode.hasFocus ? null : _formattedValue);
|
||||
inputDecoration = inputDecoration.copyWith(
|
||||
@ -1688,7 +1688,7 @@ class _HourMinuteTextFieldState extends State<_HourMinuteTextField> {
|
||||
return SizedBox(
|
||||
height: _kTimePickerHeaderControlHeight,
|
||||
child: MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 1.0),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
||||
child: TextFormField(
|
||||
autofocus: widget.autofocus ?? false,
|
||||
expands: true,
|
||||
@ -1854,7 +1854,7 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
|
||||
if (_announcedInitialTime)
|
||||
return;
|
||||
|
||||
final MediaQueryData media = MediaQuery.of(context)!;
|
||||
final MediaQueryData media = MediaQuery.of(context);
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
_announceToAccessibility(
|
||||
context,
|
||||
@ -1903,12 +1903,12 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
|
||||
}
|
||||
|
||||
Size _dialogSize(BuildContext context) {
|
||||
final Orientation orientation = MediaQuery.of(context)!.orientation;
|
||||
final Orientation orientation = MediaQuery.of(context).orientation;
|
||||
final ThemeData theme = Theme.of(context)!;
|
||||
// Constrain the textScaleFactor to prevent layout issues. Since only some
|
||||
// parts of the time picker scale up with textScaleFactor, we cap the factor
|
||||
// to 1.1 as that provides enough space to reasonably fit all the content.
|
||||
final double textScaleFactor = math.min(MediaQuery.of(context)!.textScaleFactor, 1.1);
|
||||
final double textScaleFactor = math.min(MediaQuery.of(context).textScaleFactor, 1.1);
|
||||
|
||||
final double timePickerWidth;
|
||||
final double timePickerHeight;
|
||||
@ -1940,7 +1940,7 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
final MediaQueryData media = MediaQuery.of(context)!;
|
||||
final MediaQueryData media = MediaQuery.of(context);
|
||||
final TimeOfDayFormat timeOfDayFormat = localizations.timeOfDayFormat(alwaysUse24HourFormat: media.alwaysUse24HourFormat);
|
||||
final bool use24HourDials = hourFormat(of: timeOfDayFormat) != HourFormat.h;
|
||||
final ThemeData theme = Theme.of(context)!;
|
||||
|
@ -1057,7 +1057,7 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> {
|
||||
}
|
||||
|
||||
bool canRequestFocus(FocusableActionDetector target) {
|
||||
final NavigationMode mode = MediaQuery.of(context, nullOk: true)?.navigationMode ?? NavigationMode.traditional;
|
||||
final NavigationMode mode = MediaQuery.maybeOf(context)?.navigationMode ?? NavigationMode.traditional;
|
||||
switch (mode) {
|
||||
case NavigationMode.traditional:
|
||||
return target.enabled;
|
||||
@ -1098,7 +1098,7 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> {
|
||||
}
|
||||
|
||||
bool get _canRequestFocus {
|
||||
final NavigationMode mode = MediaQuery.of(context, nullOk: true)?.navigationMode ?? NavigationMode.traditional;
|
||||
final NavigationMode mode = MediaQuery.maybeOf(context)?.navigationMode ?? NavigationMode.traditional;
|
||||
switch (mode) {
|
||||
case NavigationMode.traditional:
|
||||
return widget.enabled;
|
||||
|
@ -216,13 +216,16 @@ bool debugCheckHasMediaQuery(BuildContext context) {
|
||||
assert(() {
|
||||
if (context.widget is! MediaQuery && context.findAncestorWidgetOfExactType<MediaQuery>() == null) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('No MediaQuery widget found.'),
|
||||
ErrorSummary('No MediaQuery widget ancestor found.'),
|
||||
ErrorDescription('${context.widget.runtimeType} widgets require a MediaQuery widget ancestor.'),
|
||||
context.describeWidget('The specific widget that could not find a MediaQuery ancestor was'),
|
||||
context.describeOwnershipChain('The ownership chain for the affected widget is'),
|
||||
ErrorHint(
|
||||
'Typically, the MediaQuery widget is introduced by the MaterialApp or '
|
||||
'WidgetsApp widget at the top of your application widget tree.'
|
||||
'No MediaQuery ancestor could be found starting from the context '
|
||||
'that was passed to MediaQuery.of(). This can happen because you '
|
||||
'have not added a WidgetsApp, CupertinoApp, or MaterialApp widget '
|
||||
'(those widgets introduce a MediaQuery), or it can happen if the '
|
||||
'context you use comes from a widget above those widgets.'
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
@ -2443,7 +2443,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
|
||||
@override
|
||||
TextEditingValue get textEditingValue => _value;
|
||||
|
||||
double get _devicePixelRatio => MediaQuery.of(context)?.devicePixelRatio ?? 1.0;
|
||||
double get _devicePixelRatio => MediaQuery.of(context).devicePixelRatio;
|
||||
|
||||
@override
|
||||
set textEditingValue(TextEditingValue value) {
|
||||
|
@ -50,7 +50,7 @@ export 'package:flutter/painting.dart' show
|
||||
ImageConfiguration createLocalImageConfiguration(BuildContext context, { Size? size }) {
|
||||
return ImageConfiguration(
|
||||
bundle: DefaultAssetBundle.of(context),
|
||||
devicePixelRatio: MediaQuery.of(context, nullOk: true)?.devicePixelRatio ?? 1.0,
|
||||
devicePixelRatio: MediaQuery.maybeOf(context)?.devicePixelRatio ?? 1.0,
|
||||
locale: Localizations.localeOf(context, nullOk: true),
|
||||
textDirection: Directionality.maybeOf(context),
|
||||
size: size,
|
||||
@ -1145,7 +1145,7 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
|
||||
}
|
||||
|
||||
void _updateInvertColors() {
|
||||
_invertColors = MediaQuery.of(context, nullOk: true)?.invertColors
|
||||
_invertColors = MediaQuery.maybeOf(context)?.invertColors
|
||||
?? SemanticsBinding.instance!.accessibilityFeatures.invertColors;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import 'dart:ui' show Brightness;
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'basic.dart';
|
||||
import 'debug.dart';
|
||||
import 'framework.dart';
|
||||
|
||||
/// Whether in portrait or landscape.
|
||||
@ -683,7 +684,7 @@ class MediaQuery extends InheritedWidget {
|
||||
}) {
|
||||
return MediaQuery(
|
||||
key: key,
|
||||
data: MediaQuery.of(context)!.removePadding(
|
||||
data: MediaQuery.of(context).removePadding(
|
||||
removeLeft: removeLeft,
|
||||
removeTop: removeTop,
|
||||
removeRight: removeRight,
|
||||
@ -728,7 +729,7 @@ class MediaQuery extends InheritedWidget {
|
||||
}) {
|
||||
return MediaQuery(
|
||||
key: key,
|
||||
data: MediaQuery.of(context)!.removeViewInsets(
|
||||
data: MediaQuery.of(context).removeViewInsets(
|
||||
removeLeft: removeLeft,
|
||||
removeTop: removeTop,
|
||||
removeRight: removeRight,
|
||||
@ -772,7 +773,7 @@ class MediaQuery extends InheritedWidget {
|
||||
}) {
|
||||
return MediaQuery(
|
||||
key: key,
|
||||
data: MediaQuery.of(context)!.removeViewPadding(
|
||||
data: MediaQuery.of(context).removeViewPadding(
|
||||
removeLeft: removeLeft,
|
||||
removeTop: removeTop,
|
||||
removeRight: removeRight,
|
||||
@ -791,9 +792,10 @@ class MediaQuery extends InheritedWidget {
|
||||
/// The data from the closest instance of this class that encloses the given
|
||||
/// context.
|
||||
///
|
||||
/// You can use this function to query the size an orientation of the screen.
|
||||
/// When that information changes, your widget will be scheduled to be
|
||||
/// rebuilt, keeping your widget up-to-date.
|
||||
/// You can use this function to query the size and orientation of the screen,
|
||||
/// as well as other media parameters (see [MediaQueryData] for more
|
||||
/// examples). When that information changes, your widget will be scheduled to
|
||||
/// be rebuilt, keeping your widget up-to-date.
|
||||
///
|
||||
/// Typical usage is as follows:
|
||||
///
|
||||
@ -801,35 +803,56 @@ class MediaQuery extends InheritedWidget {
|
||||
/// MediaQueryData media = MediaQuery.of(context);
|
||||
/// ```
|
||||
///
|
||||
/// If there is no [MediaQuery] in scope, then this will throw an exception.
|
||||
/// To return null if there is no [MediaQuery], then pass `nullOk: true`.
|
||||
/// If there is no [MediaQuery] in scope, this will throw a [TypeError]
|
||||
/// exception in release builds, and throw a descriptive [FlutterError] in
|
||||
/// debug builds.
|
||||
///
|
||||
/// If you use this from a widget (e.g. in its build function), consider
|
||||
/// calling [debugCheckHasMediaQuery].
|
||||
static MediaQueryData? of(BuildContext context, { bool nullOk = false }) {
|
||||
/// See also:
|
||||
///
|
||||
/// * [maybeOf], which doesn't throw or assert if it doesn't find a
|
||||
/// [MediaQuery] ancestor, it returns null instead.
|
||||
static MediaQueryData of(BuildContext context) {
|
||||
assert(context != null);
|
||||
assert(nullOk != null);
|
||||
final MediaQuery? query = context.dependOnInheritedWidgetOfExactType<MediaQuery>();
|
||||
if (query != null)
|
||||
return query.data;
|
||||
if (nullOk)
|
||||
return null;
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('MediaQuery.of() called with a context that does not contain a MediaQuery.'),
|
||||
ErrorDescription(
|
||||
'No MediaQuery ancestor could be found starting from the context that was passed '
|
||||
'to MediaQuery.of(). This can happen because you do not have a WidgetsApp or '
|
||||
'MaterialApp widget (those widgets introduce a MediaQuery), or it can happen '
|
||||
'if the context you use comes from a widget above those widgets.'
|
||||
),
|
||||
context.describeElement('The context used was')
|
||||
]);
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
return context.dependOnInheritedWidgetOfExactType<MediaQuery>()!.data;
|
||||
}
|
||||
|
||||
/// The data from the closest instance of this class that encloses the given
|
||||
/// context, if any.
|
||||
///
|
||||
/// Use this function if you want to allow situations where no [MediaQuery] is
|
||||
/// in scope. Prefer using [MediaQuery.of] in situations where a media query
|
||||
/// is always expected to exist.
|
||||
///
|
||||
/// If there is no [MediaQuery] in scope, then this function will return null.
|
||||
///
|
||||
/// You can use this function to query the size and orientation of the screen,
|
||||
/// as well as other media parameters (see [MediaQueryData] for more
|
||||
/// examples). When that information changes, your widget will be scheduled to
|
||||
/// be rebuilt, keeping your widget up-to-date.
|
||||
///
|
||||
/// Typical usage is as follows:
|
||||
///
|
||||
/// ```dart
|
||||
/// MediaQueryData? mediaQuery = MediaQuery.maybeOf(context);
|
||||
/// if (mediaQuery == null) {
|
||||
/// // Do something else instead.
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [of], which will throw if it doesn't find a [MediaQuery] ancestor,
|
||||
/// instead of returning null.
|
||||
static MediaQueryData? maybeOf(BuildContext context) {
|
||||
assert(context != null);
|
||||
return context.dependOnInheritedWidgetOfExactType<MediaQuery>()?.data;
|
||||
}
|
||||
|
||||
/// Returns textScaleFactor for the nearest MediaQuery ancestor or 1.0, if
|
||||
/// no such ancestor exists.
|
||||
static double textScaleFactorOf(BuildContext context) {
|
||||
return MediaQuery.of(context, nullOk: true)?.textScaleFactor ?? 1.0;
|
||||
return MediaQuery.maybeOf(context)?.textScaleFactor ?? 1.0;
|
||||
}
|
||||
|
||||
/// Returns platformBrightness for the nearest MediaQuery ancestor or
|
||||
@ -838,7 +861,7 @@ class MediaQuery extends InheritedWidget {
|
||||
/// Use of this method will cause the given [context] to rebuild any time that
|
||||
/// any property of the ancestor [MediaQuery] changes.
|
||||
static Brightness platformBrightnessOf(BuildContext context) {
|
||||
return MediaQuery.of(context, nullOk: true)?.platformBrightness ?? Brightness.light;
|
||||
return MediaQuery.maybeOf(context)?.platformBrightness ?? Brightness.light;
|
||||
}
|
||||
|
||||
/// Returns highContrast for the nearest MediaQuery ancestor or false, if no
|
||||
@ -849,13 +872,13 @@ class MediaQuery extends InheritedWidget {
|
||||
/// * [MediaQueryData.highContrast], which indicates the platform's
|
||||
/// desire to increase contrast.
|
||||
static bool highContrastOf(BuildContext context) {
|
||||
return MediaQuery.of(context, nullOk: true)?.highContrast ?? false;
|
||||
return MediaQuery.maybeOf(context)?.highContrast ?? false;
|
||||
}
|
||||
|
||||
/// Returns the boldText accessibility setting for the nearest MediaQuery
|
||||
/// ancestor, or false if no such ancestor exists.
|
||||
static bool boldTextOverride(BuildContext context) {
|
||||
return MediaQuery.of(context, nullOk: true)?.boldText ?? false;
|
||||
return MediaQuery.maybeOf(context)?.boldText ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -95,7 +95,7 @@ class SafeArea extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
final MediaQueryData data = MediaQuery.of(context)!;
|
||||
final MediaQueryData data = MediaQuery.of(context);
|
||||
EdgeInsets padding = data.padding;
|
||||
// Bottom padding has been consumed - i.e. by the keyboard
|
||||
if (data.padding.bottom == 0.0 && data.viewInsets.bottom != 0.0 && maintainBottomViewPadding)
|
||||
@ -194,7 +194,7 @@ class SliverSafeArea extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
final EdgeInsets padding = MediaQuery.of(context)!.padding;
|
||||
final EdgeInsets padding = MediaQuery.of(context).padding;
|
||||
return SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
left: math.max(left ? padding.left : 0.0, minimum.left),
|
||||
|
@ -675,7 +675,7 @@ abstract class BoxScrollView extends ScrollView {
|
||||
Widget sliver = buildChildLayout(context);
|
||||
EdgeInsetsGeometry? effectivePadding = padding;
|
||||
if (padding == null) {
|
||||
final MediaQueryData? mediaQuery = MediaQuery.of(context, nullOk: true);
|
||||
final MediaQueryData? mediaQuery = MediaQuery.maybeOf(context);
|
||||
if (mediaQuery != null) {
|
||||
// Automatically pad sliver with padding from MediaQuery.
|
||||
final EdgeInsets mediaQueryHorizontalPadding =
|
||||
|
@ -283,7 +283,7 @@ void main() {
|
||||
createAppWithButtonThatLaunchesActionSheet(
|
||||
Builder(builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
|
||||
child: CupertinoActionSheet(
|
||||
title: const Text('The title'),
|
||||
message: const Text('The message.'),
|
||||
@ -348,9 +348,9 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
createAppWithButtonThatLaunchesActionSheet(
|
||||
Builder(builder: (BuildContext context) {
|
||||
screenHeight = MediaQuery.of(context)!.size.height;
|
||||
screenHeight = MediaQuery.of(context).size.height;
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
|
||||
child: CupertinoActionSheet(
|
||||
title: const Text('The title'),
|
||||
message: Text('Very long content' * 200),
|
||||
|
@ -283,7 +283,7 @@ void main() {
|
||||
|
||||
// Asserts when the required dependency is missing.
|
||||
await tester.pumpWidget(const DependentWidget(color: contrastDependentColor1));
|
||||
expect(tester.takeException()?.toString(), contains('does not contain a MediaQuery'));
|
||||
expect(tester.takeException()?.toString(), contains('No MediaQuery widget ancestor found'));
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
|
@ -1386,7 +1386,7 @@ void main() {
|
||||
home: StatefulBuilder(builder: (BuildContext context, StateSetter stateSetter) {
|
||||
setState = stateSetter;
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(platformBrightness: brightness),
|
||||
data: MediaQuery.of(context).copyWith(platformBrightness: brightness),
|
||||
child: CupertinoDatePicker(
|
||||
initialDateTime: DateTime(2019),
|
||||
mode: CupertinoDatePickerMode.date,
|
||||
|
@ -275,7 +275,7 @@ void main() {
|
||||
createAppWithButtonThatLaunchesDialog(
|
||||
dialogBuilder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
|
||||
child: CupertinoAlertDialog(
|
||||
title: const Text('The Title'),
|
||||
content: Text('Very long content ' * 20),
|
||||
@ -375,7 +375,7 @@ void main() {
|
||||
createAppWithButtonThatLaunchesDialog(
|
||||
dialogBuilder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
|
||||
child: CupertinoAlertDialog(
|
||||
title: const Text('The title'),
|
||||
content: const Text('The content.'),
|
||||
@ -436,7 +436,7 @@ void main() {
|
||||
createAppWithButtonThatLaunchesDialog(
|
||||
dialogBuilder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: textScaleFactor),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
|
||||
child: CupertinoAlertDialog(
|
||||
actions: const <Widget>[
|
||||
CupertinoDialogAction(
|
||||
@ -487,7 +487,7 @@ void main() {
|
||||
createAppWithButtonThatLaunchesDialog(
|
||||
dialogBuilder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: textScaleFactor),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
|
||||
child: CupertinoAlertDialog(
|
||||
title: const Text('The title'),
|
||||
content: const Text('The content.'),
|
||||
@ -556,7 +556,7 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
createAppWithButtonThatLaunchesDialog(
|
||||
dialogBuilder: (BuildContext context) {
|
||||
dividerWidth = 1.0 / MediaQuery.of(context)!.devicePixelRatio;
|
||||
dividerWidth = 1.0 / MediaQuery.of(context).devicePixelRatio;
|
||||
return CupertinoAlertDialog(
|
||||
title: const Text('The Title'),
|
||||
content: const Text('The message'),
|
||||
@ -601,7 +601,7 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
createAppWithButtonThatLaunchesDialog(
|
||||
dialogBuilder: (BuildContext context) {
|
||||
dividerThickness = 1.0 / MediaQuery.of(context)!.devicePixelRatio;
|
||||
dividerThickness = 1.0 / MediaQuery.of(context).devicePixelRatio;
|
||||
return CupertinoAlertDialog(
|
||||
title: const Text('The Title'),
|
||||
content: const Text('The message'),
|
||||
@ -677,7 +677,7 @@ void main() {
|
||||
createAppWithButtonThatLaunchesDialog(
|
||||
dialogBuilder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
|
||||
child: CupertinoAlertDialog(
|
||||
title: const Text('The Title'),
|
||||
content: Text('The message\n' * 20),
|
||||
@ -809,7 +809,7 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
createAppWithButtonThatLaunchesDialog(
|
||||
dialogBuilder: (BuildContext context) {
|
||||
dividerThickness = 1.0 / MediaQuery.of(context)!.devicePixelRatio;
|
||||
dividerThickness = 1.0 / MediaQuery.of(context).devicePixelRatio;
|
||||
return CupertinoAlertDialog(
|
||||
title: const Text('The Title'),
|
||||
content: const Text('The message'),
|
||||
@ -1151,7 +1151,7 @@ void main() {
|
||||
createAppWithButtonThatLaunchesDialog(
|
||||
dialogBuilder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
|
||||
child: const RepaintBoundary(
|
||||
child: CupertinoAlertDialog(
|
||||
title: Text('Title'),
|
||||
|
@ -282,7 +282,7 @@ void main() {
|
||||
MaterialApp(
|
||||
home: Builder(builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 99),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 99),
|
||||
child: CupertinoTabScaffold(
|
||||
tabBar: CupertinoTabBar(
|
||||
items: List<BottomNavigationBarItem>.generate(
|
||||
|
@ -1106,7 +1106,7 @@ void main() {
|
||||
CupertinoApp(
|
||||
home: Builder(builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 99),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 99),
|
||||
child: CupertinoPageScaffold(
|
||||
child: CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
@ -1154,7 +1154,7 @@ void main() {
|
||||
title: 'title',
|
||||
builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 99),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 99),
|
||||
child: Container(
|
||||
child: const CupertinoPageScaffold(
|
||||
child: CustomScrollView(
|
||||
|
@ -49,7 +49,7 @@ void main() {
|
||||
),
|
||||
));
|
||||
|
||||
expect(MediaQuery.of(childContext)!.padding.top, 0);
|
||||
expect(MediaQuery.of(childContext).padding.top, 0);
|
||||
// The top of the [Container] is 44 px from the top of the screen because
|
||||
// it's pushed down by the opaque navigation bar whose height is 44 px,
|
||||
// and the 20 px [MediaQuery] top padding is fully absorbed by the navigation bar.
|
||||
@ -94,12 +94,12 @@ void main() {
|
||||
}
|
||||
await tester.pumpWidget(scaffoldWithBrightness(Brightness.light));
|
||||
|
||||
expect(MediaQuery.of(childContext)!.padding.top, 0);
|
||||
expect(MediaQuery.of(childContext).padding.top, 0);
|
||||
expect(find.byType(CupertinoPageScaffold), paints..rect(color: backgroundColor.color));
|
||||
|
||||
await tester.pumpWidget(scaffoldWithBrightness(Brightness.dark));
|
||||
|
||||
expect(MediaQuery.of(childContext)!.padding.top, greaterThan(0));
|
||||
expect(MediaQuery.of(childContext).padding.top, greaterThan(0));
|
||||
expect(find.byType(CupertinoPageScaffold), paints..rect(color: backgroundColor.darkColor));
|
||||
});
|
||||
|
||||
@ -142,7 +142,7 @@ void main() {
|
||||
expect(tester.getSize(find.byType(Container)).height, 600.0 - 100.0);
|
||||
// The shouldn't see a media query view inset because it was consumed by
|
||||
// the scaffold.
|
||||
expect(MediaQuery.of(childContext)!.viewInsets.bottom, 0);
|
||||
expect(MediaQuery.of(childContext).viewInsets.bottom, 0);
|
||||
|
||||
await tester.pumpWidget(Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
@ -439,7 +439,7 @@ void main() {
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
// Acts as a 20px status bar at the root of the app.
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(padding: const EdgeInsets.only(top: 20)),
|
||||
data: MediaQuery.of(context).copyWith(padding: const EdgeInsets.only(top: 20)),
|
||||
child: child!,
|
||||
);
|
||||
},
|
||||
@ -537,7 +537,7 @@ void main() {
|
||||
CupertinoApp(
|
||||
home: Builder(builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 99),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 99),
|
||||
child: const CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text('middle'),
|
||||
|
@ -406,7 +406,7 @@ void main() {
|
||||
expect(tester.getRect(find.byType(Placeholder)), const Rect.fromLTWH(0, 0, 800, 400));
|
||||
// Don't generate more media query padding from the translucent bottom
|
||||
// tab since the tab is behind the keyboard now.
|
||||
expect(MediaQuery.of(innerContext)!.padding.bottom, 0);
|
||||
expect(MediaQuery.of(innerContext).padding.bottom, 0);
|
||||
});
|
||||
|
||||
testWidgets('Tab contents are not inset when resizeToAvoidBottomInset overridden', (WidgetTester tester) async {
|
||||
@ -433,7 +433,7 @@ void main() {
|
||||
expect(tester.getRect(find.byType(Placeholder)), const Rect.fromLTWH(0, 0, 800, 600));
|
||||
// Media query padding shows up in the inner content because it wasn't masked
|
||||
// by the view inset.
|
||||
expect(MediaQuery.of(innerContext)!.padding.bottom, 50);
|
||||
expect(MediaQuery.of(innerContext).padding.bottom, 50);
|
||||
});
|
||||
|
||||
testWidgets('Tab contents bottom padding are not consumed by viewInsets when resizeToAvoidBottomInset overridden', (WidgetTester tester) async {
|
||||
@ -502,7 +502,7 @@ void main() {
|
||||
items: List<BottomNavigationBarItem>.generate(2, tabGenerator),
|
||||
),
|
||||
tabBuilder: (BuildContext context, int index) {
|
||||
contentPadding = MediaQuery.of(context)!.padding;
|
||||
contentPadding = MediaQuery.of(context).padding;
|
||||
return const Placeholder();
|
||||
}
|
||||
),
|
||||
@ -543,7 +543,7 @@ void main() {
|
||||
);
|
||||
|
||||
expect(tester.getRect(find.byType(Placeholder)), const Rect.fromLTWH(0, 0, 800, 400));
|
||||
expect(MediaQuery.of(innerContext)!.padding.bottom, 0);
|
||||
expect(MediaQuery.of(innerContext).padding.bottom, 0);
|
||||
});
|
||||
|
||||
testWidgets('Deleting tabs after selecting them should switch to the last available tab', (WidgetTester tester) async {
|
||||
@ -1074,7 +1074,7 @@ void main() {
|
||||
CupertinoApp(
|
||||
home: Builder(builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 99),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 99),
|
||||
child: CupertinoTabScaffold(
|
||||
tabBar: CupertinoTabBar(
|
||||
items: List<BottomNavigationBarItem>.generate(
|
||||
|
@ -1957,7 +1957,7 @@ void main() {
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: textScaleFactor),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: false,
|
||||
@ -2002,7 +2002,7 @@ void main() {
|
||||
appBar: AppBar(
|
||||
centerTitle: centerTitle,
|
||||
title: MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: textScaleFactor),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
|
||||
child: const Text('Jumbo'),
|
||||
),
|
||||
),
|
||||
|
@ -464,7 +464,7 @@ void main() {
|
||||
double? textScaleFactor;
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: Builder(builder:(BuildContext context) {
|
||||
textScaleFactor = MediaQuery.of(context)!.textScaleFactor;
|
||||
textScaleFactor = MediaQuery.of(context).textScaleFactor;
|
||||
return Container();
|
||||
}),
|
||||
));
|
||||
|
@ -467,11 +467,11 @@ void main() {
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
|
||||
expect(
|
||||
MediaQuery.of(outerContext)!.padding,
|
||||
MediaQuery.of(outerContext).padding,
|
||||
const EdgeInsets.all(50.0),
|
||||
);
|
||||
expect(
|
||||
MediaQuery.of(innerContext)!.padding,
|
||||
MediaQuery.of(innerContext).padding,
|
||||
const EdgeInsets.only(left: 50.0, right: 50.0, bottom: 50.0),
|
||||
);
|
||||
});
|
||||
|
@ -169,7 +169,7 @@ void main() {
|
||||
child: CircleAvatar(
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
final MediaQueryData data = MediaQuery.of(context)!;
|
||||
final MediaQueryData data = MediaQuery.of(context);
|
||||
|
||||
// These should not change.
|
||||
expect(data.size, equals(const Size(111.0, 111.0)));
|
||||
|
@ -25,7 +25,7 @@ MaterialApp _buildAppWithDialog(Widget dialog, { ThemeData? theme, double textSc
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: textScaleFactor),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
|
||||
child: dialog,
|
||||
);
|
||||
},
|
||||
@ -1188,12 +1188,12 @@ void main() {
|
||||
|
||||
await tester.pump();
|
||||
|
||||
expect(MediaQuery.of(outerContext)!.padding, const EdgeInsets.all(50.0));
|
||||
expect(MediaQuery.of(routeContext)!.padding, EdgeInsets.zero);
|
||||
expect(MediaQuery.of(dialogContext)!.padding, EdgeInsets.zero);
|
||||
expect(MediaQuery.of(outerContext)!.viewInsets, const EdgeInsets.only(left: 25.0, bottom: 75.0));
|
||||
expect(MediaQuery.of(routeContext)!.viewInsets, const EdgeInsets.only(left: 25.0, bottom: 75.0));
|
||||
expect(MediaQuery.of(dialogContext)!.viewInsets, EdgeInsets.zero);
|
||||
expect(MediaQuery.of(outerContext).padding, const EdgeInsets.all(50.0));
|
||||
expect(MediaQuery.of(routeContext).padding, EdgeInsets.zero);
|
||||
expect(MediaQuery.of(dialogContext).padding, EdgeInsets.zero);
|
||||
expect(MediaQuery.of(outerContext).viewInsets, const EdgeInsets.only(left: 25.0, bottom: 75.0));
|
||||
expect(MediaQuery.of(routeContext).viewInsets, const EdgeInsets.only(left: 25.0, bottom: 75.0));
|
||||
expect(MediaQuery.of(dialogContext).viewInsets, EdgeInsets.zero);
|
||||
});
|
||||
|
||||
testWidgets('Dialog widget insets by viewInsets', (WidgetTester tester) async {
|
||||
|
@ -2086,7 +2086,7 @@ void main() {
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
return MaterialApp(
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
mediaQuery = MediaQuery.of(context)!;
|
||||
mediaQuery = MediaQuery.of(context);
|
||||
return MediaQuery(
|
||||
data: mediaQuery,
|
||||
child: child!,
|
||||
|
@ -766,7 +766,7 @@ void main() {
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
textScaleFactor: textScaleFactor,
|
||||
),
|
||||
child: Directionality(
|
||||
@ -902,7 +902,7 @@ void main() {
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
textScaleFactor: 2,
|
||||
),
|
||||
child: Scaffold(
|
||||
|
@ -394,7 +394,7 @@ void main() {
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (BuildContext context) {
|
||||
width = MediaQuery.of(context)!.size.width;
|
||||
width = MediaQuery.of(context).size.width;
|
||||
return CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
SliverAppBar(
|
||||
|
@ -1706,7 +1706,7 @@ void main() {
|
||||
body: Row(
|
||||
children: <Widget>[
|
||||
MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
|
||||
child: NavigationRail(
|
||||
selectedIndex: 0,
|
||||
destinations: const <NavigationRailDestination>[
|
||||
@ -2111,7 +2111,7 @@ Future<void> _pumpNavigationRail(
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(textScaleFactor: textScaleFactor),
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
|
||||
child: Scaffold(
|
||||
body: Row(
|
||||
children: <Widget>[
|
||||
|
@ -1009,7 +1009,7 @@ void main() {
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
textScaleFactor: textScaleFactor,
|
||||
),
|
||||
child: Directionality(
|
||||
@ -1148,7 +1148,7 @@ void main() {
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
textScaleFactor: 2,
|
||||
),
|
||||
child: Scaffold(
|
||||
|
@ -408,7 +408,7 @@ void main() {
|
||||
await tester.pump();
|
||||
|
||||
expect(
|
||||
MediaQuery.of(bottomSheetContext)!.padding,
|
||||
MediaQuery.of(bottomSheetContext).padding,
|
||||
const EdgeInsets.only(
|
||||
bottom: 50.0,
|
||||
left: 50.0,
|
||||
|
@ -138,7 +138,7 @@ void main() {
|
||||
return MaterialApp(
|
||||
home: Builder(builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
navigationMode: NavigationMode.directional,
|
||||
),
|
||||
child: Material(
|
||||
@ -254,7 +254,7 @@ void main() {
|
||||
MaterialApp(
|
||||
home: Builder(builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
navigationMode: NavigationMode.directional,
|
||||
),
|
||||
child: Material(
|
||||
@ -755,7 +755,7 @@ void main() {
|
||||
|
||||
await tester.pump();
|
||||
|
||||
expect(MediaQuery.of(popupContext)!.padding, EdgeInsets.zero);
|
||||
expect(MediaQuery.of(popupContext).padding, EdgeInsets.zero);
|
||||
});
|
||||
|
||||
testWidgets('Popup Menu Offset Test', (WidgetTester tester) async {
|
||||
|
@ -683,7 +683,7 @@ void main() {
|
||||
extendBody: extendBody,
|
||||
body: Builder(
|
||||
builder: (BuildContext context) {
|
||||
mediaQueryBottom = MediaQuery.of(context)!.padding.bottom;
|
||||
mediaQueryBottom = MediaQuery.of(context).padding.bottom;
|
||||
return Container(key: bodyKey);
|
||||
},
|
||||
),
|
||||
@ -756,7 +756,7 @@ void main() {
|
||||
),
|
||||
body: Builder(
|
||||
builder: (BuildContext context) {
|
||||
mediaQueryTop = MediaQuery.of(context)!.padding.top;
|
||||
mediaQueryTop = MediaQuery.of(context).padding.top;
|
||||
return Container(key: bodyKey);
|
||||
}
|
||||
),
|
||||
@ -1675,7 +1675,7 @@ void main() {
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
screenWidth = MediaQuery.of(context)!.size.width;
|
||||
screenWidth = MediaQuery.of(context).size.width;
|
||||
return Scaffold(
|
||||
endDrawer: const Drawer(
|
||||
child: Text('Drawer'),
|
||||
|
@ -804,7 +804,7 @@ void main() {
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
textScaleFactor: textScaleFactor,
|
||||
),
|
||||
child: Directionality(
|
||||
@ -946,7 +946,7 @@ void main() {
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
textScaleFactor: 2,
|
||||
),
|
||||
child: Scaffold(
|
||||
|
@ -5439,7 +5439,7 @@ void main() {
|
||||
boilerplate(
|
||||
child: Builder(builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
navigationMode: NavigationMode.directional,
|
||||
),
|
||||
child: TextField(
|
||||
@ -5460,7 +5460,7 @@ void main() {
|
||||
boilerplate(
|
||||
child: Builder(builder: (BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context)!.copyWith(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
navigationMode: NavigationMode.directional,
|
||||
),
|
||||
child: TextField(
|
||||
|
@ -111,23 +111,29 @@ void main() {
|
||||
expect(
|
||||
error.diagnostics.last.toStringDeep(),
|
||||
equalsIgnoringHashCodes(
|
||||
'Typically, the MediaQuery widget is introduced by the MaterialApp\n'
|
||||
'or WidgetsApp widget at the top of your application widget tree.\n'
|
||||
'No MediaQuery ancestor could be found starting from the context\n'
|
||||
'that was passed to MediaQuery.of(). This can happen because you\n'
|
||||
'have not added a WidgetsApp, CupertinoApp, or MaterialApp widget\n'
|
||||
'(those widgets introduce a MediaQuery), or it can happen if the\n'
|
||||
'context you use comes from a widget above those widgets.\n'
|
||||
),
|
||||
);
|
||||
expect(
|
||||
error.toStringDeep(),
|
||||
equalsIgnoringHashCodes(
|
||||
'FlutterError\n'
|
||||
' No MediaQuery widget found.\n'
|
||||
' No MediaQuery widget ancestor found.\n'
|
||||
' Builder widgets require a MediaQuery widget ancestor.\n'
|
||||
' The specific widget that could not find a MediaQuery ancestor\n'
|
||||
' was:\n'
|
||||
' Builder\n'
|
||||
' The ownership chain for the affected widget is: "Builder ←\n'
|
||||
' [root]"\n'
|
||||
' Typically, the MediaQuery widget is introduced by the MaterialApp\n'
|
||||
' or WidgetsApp widget at the top of your application widget tree.\n'
|
||||
' No MediaQuery ancestor could be found starting from the context\n'
|
||||
' that was passed to MediaQuery.of(). This can happen because you\n'
|
||||
' have not added a WidgetsApp, CupertinoApp, or MaterialApp widget\n'
|
||||
' (those widgets introduce a MediaQuery), or it can happen if the\n'
|
||||
' context you use comes from a widget above those widgets.\n'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ void main() {
|
||||
children: <Widget>[
|
||||
const Text('top', textDirection: TextDirection.ltr),
|
||||
Builder(builder: (BuildContext context) {
|
||||
innerMediaQueryPadding = MediaQuery.of(context)!.padding;
|
||||
innerMediaQueryPadding = MediaQuery.of(context).padding;
|
||||
return Container();
|
||||
}),
|
||||
],
|
||||
|
@ -24,31 +24,54 @@ void main() {
|
||||
expect(exception, isNotNull);
|
||||
expect(exception ,isFlutterError);
|
||||
final FlutterError error = exception as FlutterError;
|
||||
expect(error.diagnostics.length, 3);
|
||||
expect(error.diagnostics.last, isA<DiagnosticsProperty<Element>>());
|
||||
expect(error.diagnostics.length, 5);
|
||||
expect(error.diagnostics.last, isA<ErrorHint>());
|
||||
expect(
|
||||
error.toStringDeep(),
|
||||
equalsIgnoringHashCodes(
|
||||
'FlutterError\n'
|
||||
' MediaQuery.of() called with a context that does not contain a\n'
|
||||
' MediaQuery.\n'
|
||||
' No MediaQuery widget ancestor found.\n'
|
||||
' Builder widgets require a MediaQuery widget ancestor.\n'
|
||||
' The specific widget that could not find a MediaQuery ancestor\n'
|
||||
' was:\n'
|
||||
' Builder\n'
|
||||
' The ownership chain for the affected widget is: "Builder ←\n'
|
||||
' [root]"\n'
|
||||
' No MediaQuery ancestor could be found starting from the context\n'
|
||||
' that was passed to MediaQuery.of(). This can happen because you\n'
|
||||
' do not have a WidgetsApp or MaterialApp widget (those widgets\n'
|
||||
' introduce a MediaQuery), or it can happen if the context you use\n'
|
||||
' comes from a widget above those widgets.\n'
|
||||
' The context used was:\n'
|
||||
' Builder\n',
|
||||
' have not added a WidgetsApp, CupertinoApp, or MaterialApp widget\n'
|
||||
' (those widgets introduce a MediaQuery), or it can happen if the\n'
|
||||
' context you use comes from a widget above those widgets.\n'
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('MediaQuery defaults to null', (WidgetTester tester) async {
|
||||
testWidgets('MediaQuery.of finds a MediaQueryData when there is one', (WidgetTester tester) async {
|
||||
bool tested = false;
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(),
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
final MediaQueryData data = MediaQuery.of(context);
|
||||
expect(data, isNotNull);
|
||||
tested = true;
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
final dynamic exception = tester.takeException();
|
||||
expect(exception, isNull);
|
||||
expect(tested, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('MediaQuery.maybeOf defaults to null', (WidgetTester tester) async {
|
||||
bool tested = false;
|
||||
await tester.pumpWidget(
|
||||
Builder(
|
||||
builder: (BuildContext context) {
|
||||
final MediaQueryData? data = MediaQuery.of(context, nullOk: true);
|
||||
final MediaQueryData? data = MediaQuery.maybeOf(context);
|
||||
expect(data, isNull);
|
||||
tested = true;
|
||||
return Container();
|
||||
@ -58,7 +81,25 @@ void main() {
|
||||
expect(tested, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('MediaQueryData is sane', (WidgetTester tester) async {
|
||||
testWidgets('MediaQuery.maybeOf finds a MediaQueryData when there is one', (WidgetTester tester) async {
|
||||
bool tested = false;
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(),
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
final MediaQueryData? data = MediaQuery.maybeOf(context);
|
||||
expect(data, isNotNull);
|
||||
tested = true;
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(tested, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('MediaQueryData.fromWindow is sane', (WidgetTester tester) async {
|
||||
final MediaQueryData data = MediaQueryData.fromWindow(WidgetsBinding.instance!.window);
|
||||
expect(data, hasOneLineDescription);
|
||||
expect(data.hashCode, equals(data.copyWith().hashCode));
|
||||
@ -169,7 +210,7 @@ void main() {
|
||||
removeBottom: true,
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
unpadded = MediaQuery.of(context)!;
|
||||
unpadded = MediaQuery.of(context);
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
@ -225,7 +266,7 @@ void main() {
|
||||
context: context,
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
unpadded = MediaQuery.of(context)!;
|
||||
unpadded = MediaQuery.of(context);
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
@ -284,7 +325,7 @@ void main() {
|
||||
removeBottom: true,
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
unpadded = MediaQuery.of(context)!;
|
||||
unpadded = MediaQuery.of(context);
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
@ -340,7 +381,7 @@ void main() {
|
||||
removeBottom: true,
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
unpadded = MediaQuery.of(context)!;
|
||||
unpadded = MediaQuery.of(context);
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
@ -399,7 +440,7 @@ void main() {
|
||||
removeBottom: true,
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
unpadded = MediaQuery.of(context)!;
|
||||
unpadded = MediaQuery.of(context);
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
@ -455,7 +496,7 @@ void main() {
|
||||
removeLeft: true,
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
unpadded = MediaQuery.of(context)!;
|
||||
unpadded = MediaQuery.of(context);
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
|
@ -28,7 +28,7 @@ class TestOrientedBox extends SingleChildRenderObjectWidget {
|
||||
const TestOrientedBox({ Key? key, Widget? child }) : super(key: key, child: child);
|
||||
|
||||
Decoration _getDecoration(BuildContext context) {
|
||||
final Orientation orientation = MediaQuery.of(context)!.orientation;
|
||||
final Orientation orientation = MediaQuery.of(context).orientation;
|
||||
switch (orientation) {
|
||||
case Orientation.landscape:
|
||||
return const BoxDecoration(color: Color(0xFF00FF00));
|
||||
|
@ -2276,7 +2276,7 @@ void main() {
|
||||
await tester.pumpWidget(selectableText);
|
||||
final dynamic exception = tester.takeException();
|
||||
expect(exception, isFlutterError);
|
||||
expect(exception.toString(), startsWith('No MediaQuery widget found.\nSelectableText widgets require a MediaQuery widget ancestor.'));
|
||||
expect(exception.toString(), startsWith('No MediaQuery widget ancestor found.\nSelectableText widgets require a MediaQuery widget ancestor.'));
|
||||
});
|
||||
|
||||
testWidgets('onTap is called upon tap', (WidgetTester tester) async {
|
||||
|
Loading…
x
Reference in New Issue
Block a user