@@ -17,7 +17,7 @@ class Breakpoints {
1717 /// case that no other breakpoint is active.
1818 ///
1919 /// It is active from a width of -1 dp to infinity.
20- static const Breakpoint standard = Breakpoint (beginWidth : - 1 );
20+ static const Breakpoint standard = Breakpoint . standard ( );
2121
2222 /// A window whose width is less than 600 dp and greater than 0 dp.
2323 static const Breakpoint small = Breakpoint .small ();
@@ -86,6 +86,30 @@ class Breakpoints {
8686 /// A mobile window whose width is greater than 1600 dp.
8787 static const Breakpoint extraLargeMobile =
8888 Breakpoint .extraLarge (platform: Breakpoint .mobile);
89+
90+ /// A list of all the standard breakpoints.
91+ static const List <Breakpoint > all = < Breakpoint > [
92+ smallDesktop,
93+ smallMobile,
94+ small,
95+ mediumDesktop,
96+ mediumMobile,
97+ medium,
98+ mediumLargeDesktop,
99+ mediumLargeMobile,
100+ mediumLarge,
101+ largeDesktop,
102+ largeMobile,
103+ large,
104+ extraLargeDesktop,
105+ extraLargeMobile,
106+ extraLarge,
107+ smallAndUp,
108+ mediumAndUp,
109+ mediumLargeAndUp,
110+ largeAndUp,
111+ standard,
112+ ];
89113}
90114
91115/// A class to define the conditions that distinguish between types of
@@ -113,10 +137,19 @@ class Breakpoint {
113137 this .endWidth,
114138 this .beginHeight,
115139 this .endHeight,
116- this .platform,
117140 this .andUp = false ,
141+ this .platform,
118142 });
119143
144+ /// Returns a [Breakpoint] that can be used as a fallthrough in the
145+ /// case that no other breakpoint is active.
146+ const Breakpoint .standard ({this .platform})
147+ : beginWidth = - 1 ,
148+ endWidth = null ,
149+ beginHeight = null ,
150+ endHeight = null ,
151+ andUp = true ;
152+
120153 /// Returns a [Breakpoint] with the given constraints for a small screen.
121154 const Breakpoint .small ({this .andUp = false , this .platform})
122155 : beginWidth = 0 ,
@@ -166,7 +199,7 @@ class Breakpoint {
166199 TargetPlatform .iOS,
167200 };
168201
169- /// When set to true, it will include any size above the set width.
202+ /// When set to true, it will include any size above the set width and set height .
170203 final bool andUp;
171204
172205 /// The beginning width dp value. If left null then the [Breakpoint] will have
@@ -213,9 +246,9 @@ class Breakpoint {
213246
214247 final bool isHeightActive = isDesktop ||
215248 orientation == Orientation .portrait ||
216- (orientation == Orientation .landscape &&
217- height >= lowerBoundHeight &&
218- height < upperBoundHeight);
249+ (orientation == Orientation .landscape && andUp
250+ ? isWidthActive || height >= lowerBoundHeight
251+ : height >= lowerBoundHeight && height < upperBoundHeight);
219252
220253 return isWidthActive && isHeightActive && isRightPlatform;
221254 }
@@ -225,78 +258,40 @@ class Breakpoint {
225258 static Breakpoint ? maybeActiveBreakpointFromSlotLayout (BuildContext context) {
226259 final SlotLayout ? slotLayout =
227260 context.findAncestorWidgetOfExactType <SlotLayout >();
228- Breakpoint ? fallbackBreakpoint;
229-
230- if (slotLayout != null ) {
231- for (final MapEntry <Breakpoint , SlotLayoutConfig ?> config
232- in slotLayout.config.entries) {
233- if (config.key.isActive (context)) {
234- if (config.key.platform != null ) {
235- return config.key;
236- } else {
237- fallbackBreakpoint ?? = config.key;
238- }
239- }
240- }
241- }
242- return fallbackBreakpoint;
261+
262+ return slotLayout != null
263+ ? activeBreakpointIn (context, slotLayout.config.keys.toList ())
264+ : null ;
243265 }
244266
245267 /// Returns the default [Breakpoint] based on the [BuildContext] .
246268 static Breakpoint defaultBreakpointOf (BuildContext context) {
247- final TargetPlatform host = Theme .of (context).platform;
248- final bool isDesktop = Breakpoint .desktop.contains (host);
249- final bool isMobile = Breakpoint .mobile.contains (host);
250-
251- for (final Breakpoint breakpoint in < Breakpoint > [
252- Breakpoints .small,
253- Breakpoints .medium,
254- Breakpoints .mediumLarge,
255- Breakpoints .large,
256- Breakpoints .extraLarge,
257- ]) {
258- if (breakpoint.isActive (context)) {
259- if (isDesktop) {
260- switch (breakpoint) {
261- case Breakpoints .small:
262- return Breakpoints .smallDesktop;
263- case Breakpoints .medium:
264- return Breakpoints .mediumDesktop;
265- case Breakpoints .mediumLarge:
266- return Breakpoints .mediumLargeDesktop;
267- case Breakpoints .large:
268- return Breakpoints .largeDesktop;
269- case Breakpoints .extraLarge:
270- return Breakpoints .extraLargeDesktop;
271- default :
272- return Breakpoints .standard;
273- }
274- } else if (isMobile) {
275- switch (breakpoint) {
276- case Breakpoints .small:
277- return Breakpoints .smallMobile;
278- case Breakpoints .medium:
279- return Breakpoints .mediumMobile;
280- case Breakpoints .mediumLarge:
281- return Breakpoints .mediumLargeMobile;
282- case Breakpoints .large:
283- return Breakpoints .largeMobile;
284- case Breakpoints .extraLarge:
285- return Breakpoints .extraLargeMobile;
286- default :
287- return Breakpoints .standard;
288- }
289- } else {
290- return breakpoint;
291- }
292- }
293- }
294- return Breakpoints .standard;
269+ return activeBreakpointIn (context, Breakpoints .all) ?? Breakpoints .standard;
295270 }
296271
297272 /// Returns the currently active [Breakpoint] .
298273 static Breakpoint activeBreakpointOf (BuildContext context) {
299274 return maybeActiveBreakpointFromSlotLayout (context) ??
300275 defaultBreakpointOf (context);
301276 }
277+
278+ /// Returns the currently active [Breakpoint] based on the [BuildContext] and
279+ /// a list of [Breakpoint] s.
280+ static Breakpoint ? activeBreakpointIn (
281+ BuildContext context, List <Breakpoint > breakpoints) {
282+ Breakpoint ? currentBreakpoint;
283+
284+ for (final Breakpoint breakpoint in breakpoints) {
285+ if (breakpoint.isActive (context)) {
286+ if (breakpoint.platform != null ) {
287+ // Prioritize platform-specific breakpoints.
288+ return breakpoint;
289+ } else {
290+ // Fallback to non-platform-specific.
291+ currentBreakpoint = breakpoint;
292+ }
293+ }
294+ }
295+ return currentBreakpoint;
296+ }
302297}
0 commit comments