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