Skip to content

Commit fd360c4

Browse files
authored
Prevent Mediaquery from losing navigationMode value when removePadding() is called (flutter#101938)
1 parent 7b7206e commit fd360c4

File tree

2 files changed

+18
-43
lines changed

2 files changed

+18
-43
lines changed

packages/flutter/lib/src/widgets/media_query.dart

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,7 @@ class MediaQueryData {
438438
}) {
439439
if (!(removeLeft || removeTop || removeRight || removeBottom))
440440
return this;
441-
return MediaQueryData(
442-
size: size,
443-
devicePixelRatio: devicePixelRatio,
444-
textScaleFactor: textScaleFactor,
445-
platformBrightness: platformBrightness,
441+
return copyWith(
446442
padding: padding.copyWith(
447443
left: removeLeft ? 0.0 : null,
448444
top: removeTop ? 0.0 : null,
@@ -455,15 +451,6 @@ class MediaQueryData {
455451
right: removeRight ? math.max(0.0, viewPadding.right - padding.right) : null,
456452
bottom: removeBottom ? math.max(0.0, viewPadding.bottom - padding.bottom) : null,
457453
),
458-
viewInsets: viewInsets,
459-
alwaysUse24HourFormat: alwaysUse24HourFormat,
460-
highContrast: highContrast,
461-
disableAnimations: disableAnimations,
462-
invertColors: invertColors,
463-
accessibleNavigation: accessibleNavigation,
464-
boldText: boldText,
465-
gestureSettings: gestureSettings,
466-
displayFeatures: displayFeatures,
467454
);
468455
}
469456

@@ -488,12 +475,7 @@ class MediaQueryData {
488475
}) {
489476
if (!(removeLeft || removeTop || removeRight || removeBottom))
490477
return this;
491-
return MediaQueryData(
492-
size: size,
493-
devicePixelRatio: devicePixelRatio,
494-
textScaleFactor: textScaleFactor,
495-
platformBrightness: platformBrightness,
496-
padding: padding,
478+
return copyWith(
497479
viewPadding: viewPadding.copyWith(
498480
left: removeLeft ? math.max(0.0, viewPadding.left - viewInsets.left) : null,
499481
top: removeTop ? math.max(0.0, viewPadding.top - viewInsets.top) : null,
@@ -506,14 +488,6 @@ class MediaQueryData {
506488
right: removeRight ? 0.0 : null,
507489
bottom: removeBottom ? 0.0 : null,
508490
),
509-
alwaysUse24HourFormat: alwaysUse24HourFormat,
510-
highContrast: highContrast,
511-
disableAnimations: disableAnimations,
512-
invertColors: invertColors,
513-
accessibleNavigation: accessibleNavigation,
514-
boldText: boldText,
515-
gestureSettings: gestureSettings,
516-
displayFeatures: displayFeatures,
517491
);
518492
}
519493

@@ -538,32 +512,19 @@ class MediaQueryData {
538512
}) {
539513
if (!(removeLeft || removeTop || removeRight || removeBottom))
540514
return this;
541-
return MediaQueryData(
542-
size: size,
543-
devicePixelRatio: devicePixelRatio,
544-
textScaleFactor: textScaleFactor,
545-
platformBrightness: platformBrightness,
515+
return copyWith(
546516
padding: padding.copyWith(
547517
left: removeLeft ? 0.0 : null,
548518
top: removeTop ? 0.0 : null,
549519
right: removeRight ? 0.0 : null,
550520
bottom: removeBottom ? 0.0 : null,
551521
),
552-
viewInsets: viewInsets,
553522
viewPadding: viewPadding.copyWith(
554523
left: removeLeft ? 0.0 : null,
555524
top: removeTop ? 0.0 : null,
556525
right: removeRight ? 0.0 : null,
557526
bottom: removeBottom ? 0.0 : null,
558527
),
559-
alwaysUse24HourFormat: alwaysUse24HourFormat,
560-
highContrast: highContrast,
561-
disableAnimations: disableAnimations,
562-
invertColors: invertColors,
563-
accessibleNavigation: accessibleNavigation,
564-
boldText: boldText,
565-
gestureSettings: gestureSettings,
566-
displayFeatures: displayFeatures,
567528
);
568529
}
569530

packages/flutter/test/widgets/media_query_test.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ void main() {
171171
boldText: true,
172172
highContrast: true,
173173
platformBrightness: Brightness.dark,
174+
navigationMode: NavigationMode.directional,
174175
gestureSettings: gestureSettings,
175176
displayFeatures: customDisplayFeatures,
176177
);
@@ -188,6 +189,7 @@ void main() {
188189
expect(copied.boldText, true);
189190
expect(copied.highContrast, true);
190191
expect(copied.platformBrightness, Brightness.dark);
192+
expect(copied.navigationMode, NavigationMode.directional);
191193
expect(copied.gestureSettings, gestureSettings);
192194
expect(copied.displayFeatures, customDisplayFeatures);
193195
});
@@ -223,6 +225,7 @@ void main() {
223225
disableAnimations: true,
224226
boldText: true,
225227
highContrast: true,
228+
navigationMode: NavigationMode.directional,
226229
displayFeatures: displayFeatures,
227230
),
228231
child: Builder(
@@ -257,6 +260,7 @@ void main() {
257260
expect(unpadded.disableAnimations, true);
258261
expect(unpadded.boldText, true);
259262
expect(unpadded.highContrast, true);
263+
expect(unpadded.navigationMode, NavigationMode.directional);
260264
expect(unpadded.displayFeatures, displayFeatures);
261265
});
262266

@@ -291,6 +295,7 @@ void main() {
291295
disableAnimations: true,
292296
boldText: true,
293297
highContrast: true,
298+
navigationMode: NavigationMode.directional,
294299
displayFeatures: displayFeatures,
295300
),
296301
child: Builder(
@@ -322,6 +327,7 @@ void main() {
322327
expect(unpadded.disableAnimations, true);
323328
expect(unpadded.boldText, true);
324329
expect(unpadded.highContrast, true);
330+
expect(unpadded.navigationMode, NavigationMode.directional);
325331
expect(unpadded.displayFeatures, displayFeatures);
326332
});
327333

@@ -356,6 +362,7 @@ void main() {
356362
disableAnimations: true,
357363
boldText: true,
358364
highContrast: true,
365+
navigationMode: NavigationMode.directional,
359366
displayFeatures: displayFeatures,
360367
),
361368
child: Builder(
@@ -390,6 +397,7 @@ void main() {
390397
expect(unpadded.disableAnimations, true);
391398
expect(unpadded.boldText, true);
392399
expect(unpadded.highContrast, true);
400+
expect(unpadded.navigationMode, NavigationMode.directional);
393401
expect(unpadded.displayFeatures, displayFeatures);
394402
});
395403

@@ -424,6 +432,7 @@ void main() {
424432
disableAnimations: true,
425433
boldText: true,
426434
highContrast: true,
435+
navigationMode: NavigationMode.directional,
427436
displayFeatures: displayFeatures,
428437
),
429438
child: Builder(
@@ -455,6 +464,7 @@ void main() {
455464
expect(unpadded.disableAnimations, true);
456465
expect(unpadded.boldText, true);
457466
expect(unpadded.highContrast, true);
467+
expect(unpadded.navigationMode, NavigationMode.directional);
458468
expect(unpadded.displayFeatures, displayFeatures);
459469
});
460470

@@ -489,6 +499,7 @@ void main() {
489499
disableAnimations: true,
490500
boldText: true,
491501
highContrast: true,
502+
navigationMode: NavigationMode.directional,
492503
displayFeatures: displayFeatures,
493504
),
494505
child: Builder(
@@ -523,6 +534,7 @@ void main() {
523534
expect(unpadded.disableAnimations, true);
524535
expect(unpadded.boldText, true);
525536
expect(unpadded.highContrast, true);
537+
expect(unpadded.navigationMode, NavigationMode.directional);
526538
expect(unpadded.displayFeatures, displayFeatures);
527539
});
528540

@@ -557,6 +569,7 @@ void main() {
557569
disableAnimations: true,
558570
boldText: true,
559571
highContrast: true,
572+
navigationMode: NavigationMode.directional,
560573
displayFeatures: displayFeatures,
561574
),
562575
child: Builder(
@@ -588,6 +601,7 @@ void main() {
588601
expect(unpadded.disableAnimations, true);
589602
expect(unpadded.boldText, true);
590603
expect(unpadded.highContrast, true);
604+
expect(unpadded.navigationMode, NavigationMode.directional);
591605
expect(unpadded.displayFeatures, displayFeatures);
592606
});
593607

@@ -900,7 +914,7 @@ void main() {
900914
);
901915
expect(
902916
subScreenMediaQuery.viewPadding,
903-
const EdgeInsets.only(top: 6.0, left:4.0, right: 8.0, bottom: 12.0),
917+
const EdgeInsets.only(top: 6.0, left: 4.0, right: 8.0, bottom: 12.0),
904918
);
905919
expect(
906920
subScreenMediaQuery.viewInsets,

0 commit comments

Comments
 (0)