mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Replace MediaQuery.sizeOf with heightOf and widthOf. (#168479)
Closes https://github.com/flutter/flutter/issues/168478 ### Description - Replaces `MediaQuery.sizeOf(context).height` with `MediaQuery.heightOf(context)` - Replaces `MediaQuery.sizeOf(context).width` with `MediaQuery.widthOf(context)` ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
parent
9d8e5e0b2f
commit
bc74369513
@ -412,7 +412,7 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
|
||||
// it.
|
||||
_ContextMenuLocation get _contextMenuLocation {
|
||||
final Rect childRect = _getRect(_childGlobalKey);
|
||||
final double screenWidth = MediaQuery.sizeOf(context).width;
|
||||
final double screenWidth = MediaQuery.widthOf(context);
|
||||
|
||||
final double center = screenWidth / 2;
|
||||
final bool centerDividesChild = childRect.left < center && childRect.right > center;
|
||||
@ -1250,7 +1250,7 @@ class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic>
|
||||
Widget _buildChildAnimation(BuildContext context, Widget? child) {
|
||||
_lastScale = _getScale(
|
||||
widget.orientation,
|
||||
MediaQuery.sizeOf(context).height,
|
||||
MediaQuery.heightOf(context),
|
||||
_moveAnimation.value.dy,
|
||||
);
|
||||
return Transform.scale(key: widget.childGlobalKey, scale: _lastScale, child: child);
|
||||
|
||||
@ -171,7 +171,7 @@ class _CupertinoDesktopTextSelectionControlsToolbarState
|
||||
clampDouble(
|
||||
widget.selectionMidpoint.dx - widget.globalEditableRegion.left,
|
||||
mediaQueryPadding.left,
|
||||
MediaQuery.sizeOf(context).width - mediaQueryPadding.right,
|
||||
MediaQuery.widthOf(context) - mediaQueryPadding.right,
|
||||
),
|
||||
widget.selectionMidpoint.dy - widget.globalEditableRegion.top,
|
||||
);
|
||||
|
||||
@ -1320,8 +1320,8 @@ class _CupertinoActionSheetState extends State<CupertinoActionSheet> {
|
||||
if (widget.cancelButton != null) _buildCancelButton(),
|
||||
];
|
||||
final double actionSheetWidth = switch (MediaQuery.orientationOf(context)) {
|
||||
Orientation.portrait => MediaQuery.sizeOf(context).width,
|
||||
Orientation.landscape => MediaQuery.sizeOf(context).height,
|
||||
Orientation.portrait => MediaQuery.widthOf(context),
|
||||
Orientation.landscape => MediaQuery.heightOf(context),
|
||||
};
|
||||
|
||||
return SafeArea(
|
||||
|
||||
@ -492,7 +492,7 @@ class CupertinoSheetRoute<T> extends PageRoute<T> with _CupertinoSheetRouteTrans
|
||||
|
||||
@override
|
||||
Widget buildContent(BuildContext context) {
|
||||
final double topPadding = MediaQuery.sizeOf(context).height * _kTopGapRatio;
|
||||
final double topPadding = MediaQuery.heightOf(context) * _kTopGapRatio;
|
||||
return MediaQuery.removePadding(
|
||||
context: context,
|
||||
removeTop: true,
|
||||
|
||||
@ -266,7 +266,7 @@ class _CupertinoTextSelectionControlsToolbarState
|
||||
final double anchorX = clampDouble(
|
||||
widget.selectionMidpoint.dx + widget.globalEditableRegion.left,
|
||||
_kArrowScreenPadding + mediaQueryPadding.left,
|
||||
MediaQuery.sizeOf(context).width - mediaQueryPadding.right - _kArrowScreenPadding,
|
||||
MediaQuery.widthOf(context) - mediaQueryPadding.right - _kArrowScreenPadding,
|
||||
);
|
||||
|
||||
final double topAmountInEditableRegion =
|
||||
|
||||
@ -156,7 +156,7 @@ class CupertinoTextSelectionToolbar extends StatelessWidget {
|
||||
// too close to the horizontal edges of the screen.
|
||||
final double leftMargin = _kArrowScreenPadding + mediaQueryPadding.left;
|
||||
final double rightMargin =
|
||||
MediaQuery.sizeOf(context).width - mediaQueryPadding.right - _kArrowScreenPadding;
|
||||
MediaQuery.widthOf(context) - mediaQueryPadding.right - _kArrowScreenPadding;
|
||||
|
||||
final Offset anchorAboveAdjusted = Offset(
|
||||
clampDouble(anchorAbove.dx, leftMargin, rightMargin),
|
||||
|
||||
@ -1203,9 +1203,7 @@ const double _wideGutterSize = 24.0;
|
||||
const double _narrowGutterSize = 12.0;
|
||||
|
||||
double _getGutterSize(BuildContext context) =>
|
||||
MediaQuery.sizeOf(context).width >= _materialGutterThreshold
|
||||
? _wideGutterSize
|
||||
: _narrowGutterSize;
|
||||
MediaQuery.widthOf(context) >= _materialGutterThreshold ? _wideGutterSize : _narrowGutterSize;
|
||||
|
||||
/// Signature for the builder callback used by [_MasterDetailFlow].
|
||||
typedef _MasterViewBuilder = Widget Function(BuildContext context, bool isLateralUI);
|
||||
@ -1659,7 +1657,7 @@ class _DetailView extends StatelessWidget {
|
||||
if (_arguments == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final double screenHeight = MediaQuery.sizeOf(context).height;
|
||||
final double screenHeight = MediaQuery.heightOf(context);
|
||||
final double minHeight = (screenHeight - kToolbarHeight) / screenHeight;
|
||||
|
||||
return DraggableScrollableSheet(
|
||||
|
||||
@ -1167,7 +1167,7 @@ class _Bar extends StatelessWidget {
|
||||
alignedChild = Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
heightFactor: 1,
|
||||
child: SizedBox(width: MediaQuery.sizeOf(context).height, child: child),
|
||||
child: SizedBox(width: MediaQuery.heightOf(context), child: child),
|
||||
);
|
||||
}
|
||||
return Material(elevation: elevation, color: color, child: alignedChild);
|
||||
|
||||
@ -1879,7 +1879,7 @@ class _CalendarRangePickerDialog extends StatelessWidget {
|
||||
preferredSize: const Size(double.infinity, 64),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
SizedBox(width: MediaQuery.sizeOf(context).width < 360 ? 42 : 72),
|
||||
SizedBox(width: MediaQuery.widthOf(context) < 360 ? 42 : 72),
|
||||
Expanded(
|
||||
child: Semantics(
|
||||
label: '$helpText $startDateText to $endDateText',
|
||||
|
||||
@ -187,7 +187,7 @@ class _DesktopTextSelectionControlsToolbarState
|
||||
clampDouble(
|
||||
widget.selectionMidpoint.dx - widget.globalEditableRegion.left,
|
||||
mediaQueryPadding.left,
|
||||
MediaQuery.sizeOf(context).width - mediaQueryPadding.right,
|
||||
MediaQuery.widthOf(context) - mediaQueryPadding.right,
|
||||
),
|
||||
widget.selectionMidpoint.dy - widget.globalEditableRegion.top,
|
||||
);
|
||||
|
||||
@ -189,8 +189,7 @@ class _PredictiveBackPageTransition extends StatelessWidget {
|
||||
final Widget child;
|
||||
|
||||
Widget _secondaryAnimatedBuilder(BuildContext context, Widget? child) {
|
||||
final Size size = MediaQuery.sizeOf(context);
|
||||
final double screenWidth = size.width;
|
||||
final double screenWidth = MediaQuery.widthOf(context);
|
||||
final double xShift = (screenWidth / _screenWidthDivisionFactor) - _xShiftAdjustment;
|
||||
|
||||
final bool isCurrent = getIsCurrent();
|
||||
@ -233,8 +232,7 @@ class _PredictiveBackPageTransition extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _primaryAnimatedBuilder(BuildContext context, Widget? child) {
|
||||
final Size size = MediaQuery.sizeOf(context);
|
||||
final double screenWidth = size.width;
|
||||
final double screenWidth = MediaQuery.widthOf(context);
|
||||
final double xShift = (screenWidth / _screenWidthDivisionFactor) - _xShiftAdjustment;
|
||||
|
||||
final Animatable<double> xShiftTween = TweenSequence<double>(<TweenSequenceItem<double>>[
|
||||
|
||||
@ -723,7 +723,7 @@ class _SnackBarState extends State<SnackBar> {
|
||||
defaults.insetPadding!;
|
||||
|
||||
final double snackBarWidth =
|
||||
widget.width ?? MediaQuery.sizeOf(context).width - (margin.left + margin.right);
|
||||
widget.width ?? MediaQuery.widthOf(context) - (margin.left + margin.right);
|
||||
final double actionOverflowThreshold =
|
||||
widget.actionOverflowThreshold ??
|
||||
snackBarTheme.actionOverflowThreshold ??
|
||||
|
||||
@ -1244,7 +1244,7 @@ enum ResizeImagePolicy {
|
||||
/// Image(
|
||||
/// image: ResizeImage(
|
||||
/// FileImage(File('path/to/image')),
|
||||
/// width: MediaQuery.sizeOf(context).width ~/ 2, // Half of the screen's width.
|
||||
/// width: MediaQuery.widthOf(context) ~/ 2, // Half of the screen's width.
|
||||
/// ),
|
||||
/// );
|
||||
/// ```
|
||||
|
||||
@ -798,8 +798,6 @@ class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndi
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Size size = MediaQuery.sizeOf(context);
|
||||
double mainAxisSize;
|
||||
return NotificationListener<ScrollNotification>(
|
||||
onNotification: _handleScrollNotification,
|
||||
child: AnimatedBuilder(
|
||||
@ -808,14 +806,15 @@ class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndi
|
||||
final double stretch = _stretchController.value;
|
||||
double x = 1.0;
|
||||
double y = 1.0;
|
||||
final double mainAxisSize;
|
||||
|
||||
switch (widget.axis) {
|
||||
case Axis.horizontal:
|
||||
x += stretch;
|
||||
mainAxisSize = size.width;
|
||||
mainAxisSize = MediaQuery.widthOf(context);
|
||||
case Axis.vertical:
|
||||
y += stretch;
|
||||
mainAxisSize = size.height;
|
||||
mainAxisSize = MediaQuery.heightOf(context);
|
||||
}
|
||||
|
||||
final AlignmentGeometry alignment = _getAlignmentForAxisDirection(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user