Skip to content

Commit 6e26197

Browse files
authored
[flutter_adaptive_scaffold] Fix breakpoint not being active in certain cases like foldables (flutter#7549)
*Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.* As pointed out by the docs on this: > Available width and height are classified separately, so at any point in time, your app has two window size classes�one for width, one for height. Available width is usually more important than available height due to the ubiquity of vertical scrolling, so the width window size class is likely more relevant to your app's UI. *List which issues are fixed by this PR. You must list at least one issue.*
1 parent fdc84ec commit 6e26197

File tree

5 files changed

+116
-8
lines changed

5 files changed

+116
-8
lines changed

packages/flutter_adaptive_scaffold/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.5
2+
3+
* Fix breakpoint not being active in certain cases like foldables.
4+
15
## 0.2.4
26

37
* Compare breakpoints to each other using operators.

packages/flutter_adaptive_scaffold/lib/src/breakpoints.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ class Breakpoint {
284284
final double width = MediaQuery.sizeOf(context).width;
285285
final double height = MediaQuery.sizeOf(context).height;
286286
final Orientation orientation = MediaQuery.orientationOf(context);
287+
final bool isPortrait = orientation == Orientation.portrait;
287288

288289
final double lowerBoundWidth = beginWidth ?? double.negativeInfinity;
289290
final double upperBoundWidth = endWidth ?? double.infinity;
@@ -295,11 +296,9 @@ class Breakpoint {
295296
? width >= lowerBoundWidth
296297
: width >= lowerBoundWidth && width < upperBoundWidth;
297298

298-
final bool isHeightActive = isDesktop(context) ||
299-
orientation == Orientation.portrait ||
300-
(orientation == Orientation.landscape && andUp
301-
? isWidthActive || height >= lowerBoundHeight
302-
: height >= lowerBoundHeight && height < upperBoundHeight);
299+
final bool isHeightActive = isPortrait || isWidthActive || andUp
300+
? isWidthActive || height >= lowerBoundHeight
301+
: height >= lowerBoundHeight && height < upperBoundHeight;
303302

304303
return isWidthActive && isHeightActive && isRightPlatform;
305304
}

packages/flutter_adaptive_scaffold/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_adaptive_scaffold
22
description: Widgets to easily build adaptive layouts, including navigation elements.
3-
version: 0.2.4
3+
version: 0.2.5
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_adaptive_scaffold%22
55
repository: https://github.com/flutter/packages/tree/main/packages/flutter_adaptive_scaffold
66

packages/flutter_adaptive_scaffold/test/breakpoint_test.dart

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,23 @@ void main() {
517517
await tester.pumpAndSettle();
518518
expect(find.byKey(const Key('Breakpoints.smallMobile')), findsOneWidget);
519519
expect(find.byKey(const Key('Breakpoints.mediumMobile')), findsNothing);
520+
expect(find.byKey(const Key('Breakpoints.small')), findsNothing);
521+
expect(find.byKey(const Key('Breakpoints.smallDesktop')), findsNothing);
522+
expect(find.byKey(const Key('Breakpoints.medium')), findsNothing);
523+
expect(find.byKey(const Key('Breakpoints.mediumDesktop')), findsNothing);
524+
expect(find.byKey(const Key('Breakpoints.mediumLarge')), findsNothing);
525+
expect(
526+
find.byKey(const Key('Breakpoints.mediumLargeMobile')), findsNothing);
527+
expect(find.byKey(const Key('Breakpoints.mediumLargeDesktop')),
528+
findsNothing);
529+
expect(find.byKey(const Key('Breakpoints.large')), findsNothing);
530+
expect(find.byKey(const Key('Breakpoints.largeMobile')), findsNothing);
531+
expect(find.byKey(const Key('Breakpoints.largeDesktop')), findsNothing);
532+
expect(find.byKey(const Key('Breakpoints.extraLarge')), findsNothing);
533+
expect(
534+
find.byKey(const Key('Breakpoints.extraLargeMobile')), findsNothing);
535+
expect(
536+
find.byKey(const Key('Breakpoints.extraLargeDesktop')), findsNothing);
520537
});
521538

522539
testWidgets(
@@ -526,7 +543,24 @@ void main() {
526543
SimulatedLayout.smallLandscapeMediumPortrait.slot(tester));
527544
await tester.pumpAndSettle();
528545
expect(find.byKey(const Key('Breakpoints.smallMobile')), findsNothing);
529-
expect(find.byKey(const Key('Breakpoints.mediumMobile')), findsNothing);
546+
expect(find.byKey(const Key('Breakpoints.mediumMobile')), findsOneWidget);
547+
expect(find.byKey(const Key('Breakpoints.small')), findsNothing);
548+
expect(find.byKey(const Key('Breakpoints.smallDesktop')), findsNothing);
549+
expect(find.byKey(const Key('Breakpoints.medium')), findsNothing);
550+
expect(find.byKey(const Key('Breakpoints.mediumDesktop')), findsNothing);
551+
expect(find.byKey(const Key('Breakpoints.mediumLarge')), findsNothing);
552+
expect(
553+
find.byKey(const Key('Breakpoints.mediumLargeMobile')), findsNothing);
554+
expect(find.byKey(const Key('Breakpoints.mediumLargeDesktop')),
555+
findsNothing);
556+
expect(find.byKey(const Key('Breakpoints.large')), findsNothing);
557+
expect(find.byKey(const Key('Breakpoints.largeMobile')), findsNothing);
558+
expect(find.byKey(const Key('Breakpoints.largeDesktop')), findsNothing);
559+
expect(find.byKey(const Key('Breakpoints.extraLarge')), findsNothing);
560+
expect(
561+
find.byKey(const Key('Breakpoints.extraLargeMobile')), findsNothing);
562+
expect(
563+
find.byKey(const Key('Breakpoints.extraLargeDesktop')), findsNothing);
530564
});
531565

532566
testWidgets(
@@ -537,6 +571,22 @@ void main() {
537571
await tester.pumpAndSettle();
538572
expect(find.byKey(const Key('Breakpoints.smallMobile')), findsOneWidget);
539573
expect(find.byKey(const Key('Breakpoints.largeMobile')), findsNothing);
574+
expect(find.byKey(const Key('Breakpoints.small')), findsNothing);
575+
expect(find.byKey(const Key('Breakpoints.smallDesktop')), findsNothing);
576+
expect(find.byKey(const Key('Breakpoints.medium')), findsNothing);
577+
expect(find.byKey(const Key('Breakpoints.mediumDesktop')), findsNothing);
578+
expect(find.byKey(const Key('Breakpoints.mediumLarge')), findsNothing);
579+
expect(
580+
find.byKey(const Key('Breakpoints.mediumLargeMobile')), findsNothing);
581+
expect(find.byKey(const Key('Breakpoints.mediumLargeDesktop')),
582+
findsNothing);
583+
expect(find.byKey(const Key('Breakpoints.large')), findsNothing);
584+
expect(find.byKey(const Key('Breakpoints.largeDesktop')), findsNothing);
585+
expect(find.byKey(const Key('Breakpoints.extraLarge')), findsNothing);
586+
expect(
587+
find.byKey(const Key('Breakpoints.extraLargeMobile')), findsNothing);
588+
expect(
589+
find.byKey(const Key('Breakpoints.extraLargeDesktop')), findsNothing);
540590
});
541591

542592
testWidgets(
@@ -547,6 +597,48 @@ void main() {
547597
await tester.pumpAndSettle();
548598
expect(find.byKey(const Key('Breakpoints.smallMobile')), findsNothing);
549599
expect(find.byKey(const Key('Breakpoints.largeMobile')), findsNothing);
600+
expect(find.byKey(const Key('Breakpoints.small')), findsNothing);
601+
expect(find.byKey(const Key('Breakpoints.smallDesktop')), findsNothing);
602+
expect(find.byKey(const Key('Breakpoints.medium')), findsNothing);
603+
expect(find.byKey(const Key('Breakpoints.mediumDesktop')), findsNothing);
604+
expect(find.byKey(const Key('Breakpoints.mediumLarge')), findsNothing);
605+
expect(find.byKey(const Key('Breakpoints.mediumLargeMobile')),
606+
findsOneWidget);
607+
expect(find.byKey(const Key('Breakpoints.mediumLargeDesktop')),
608+
findsNothing);
609+
expect(find.byKey(const Key('Breakpoints.large')), findsNothing);
610+
expect(find.byKey(const Key('Breakpoints.largeDesktop')), findsNothing);
611+
expect(find.byKey(const Key('Breakpoints.extraLarge')), findsNothing);
612+
expect(
613+
find.byKey(const Key('Breakpoints.extraLargeMobile')), findsNothing);
614+
expect(
615+
find.byKey(const Key('Breakpoints.extraLargeDesktop')), findsNothing);
616+
});
617+
618+
testWidgets(
619+
'Layout for mediumLargeLandscapeMediumPortrait shows correct slot configuration',
620+
(WidgetTester tester) async {
621+
await tester.pumpWidget(
622+
SimulatedLayout.mediumLargeLandscapeMediumPortrait.slot(tester));
623+
await tester.pumpAndSettle();
624+
expect(find.byKey(const Key('Breakpoints.smallMobile')), findsNothing);
625+
expect(find.byKey(const Key('Breakpoints.largeMobile')), findsNothing);
626+
expect(find.byKey(const Key('Breakpoints.small')), findsNothing);
627+
expect(find.byKey(const Key('Breakpoints.smallDesktop')), findsNothing);
628+
expect(find.byKey(const Key('Breakpoints.medium')), findsNothing);
629+
expect(find.byKey(const Key('Breakpoints.mediumDesktop')), findsNothing);
630+
expect(find.byKey(const Key('Breakpoints.mediumLarge')), findsNothing);
631+
expect(find.byKey(const Key('Breakpoints.mediumLargeMobile')),
632+
findsOneWidget);
633+
expect(find.byKey(const Key('Breakpoints.mediumLargeDesktop')),
634+
findsNothing);
635+
expect(find.byKey(const Key('Breakpoints.large')), findsNothing);
636+
expect(find.byKey(const Key('Breakpoints.largeDesktop')), findsNothing);
637+
expect(find.byKey(const Key('Breakpoints.extraLarge')), findsNothing);
638+
expect(
639+
find.byKey(const Key('Breakpoints.extraLargeMobile')), findsNothing);
640+
expect(
641+
find.byKey(const Key('Breakpoints.extraLargeDesktop')), findsNothing);
550642
});
551643
});
552644

@@ -673,6 +765,17 @@ void main() {
673765
expect(find.byKey(const Key('Breakpoints.small')), findsNothing);
674766
expect(find.byKey(const Key('Breakpoints.mediumAndUp')), findsOneWidget);
675767
});
768+
769+
testWidgets(
770+
'slotAndUp shows correct slot for mediumLargeLandscapeMediumPortrait layout',
771+
(WidgetTester tester) async {
772+
// mediumLargeLandscapeMediumPortrait layout should show the mediumAndUp slot.
773+
await tester.pumpWidget(
774+
SimulatedLayout.mediumLargeLandscapeMediumPortrait.slotAndUp(tester));
775+
await tester.pumpAndSettle();
776+
expect(find.byKey(const Key('Breakpoints.small')), findsNothing);
777+
expect(find.byKey(const Key('Breakpoints.mediumAndUp')), findsOneWidget);
778+
});
676779
});
677780

678781
// Test for `spacing`.

packages/flutter_adaptive_scaffold/test/simulated_layout.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ enum SimulatedLayout {
123123
smallPortraitMediumLargeLandscape(
124124
width: 360, height: 900, navSlotKey: 'bottomNavigation'),
125125
smallLandscapeMediumLargePortrait(
126-
width: 900, height: 360, navSlotKey: 'primaryNavigation');
126+
width: 900, height: 360, navSlotKey: 'primaryNavigation'),
127+
mediumLargeLandscapeMediumPortrait(
128+
width: 841, height: 668, navSlotKey: 'primaryNavigation');
127129

128130
const SimulatedLayout({
129131
required double width,

0 commit comments

Comments
 (0)