Skip to content

Commit 7f8b3a9

Browse files
committed
Update Breakpoints Comparator API
- Update API to match Conditionals API.
1 parent 03da742 commit 7f8b3a9

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Use the labels you defined for layouts and values.
5959

6060
```dart
6161
// Example: if the screen is bigger than the Mobile breakpoint, build full width AppBar icons and labels.
62-
if (ResponsiveBreakpoints.of(context).isLargerThan(MOBILE))
62+
if (ResponsiveBreakpoints.of(context).largerThan(MOBILE))
6363
FullWidthAppBarItems()
6464
6565
// Booleans
@@ -70,8 +70,9 @@ ResponsiveBreakpoints.of(context).isPhone;
7070
7171
// Conditionals
7272
ResponsiveBreakpoints.of(context).equals(DESKTOP)
73-
ResponsiveBreakpoints.of(context).isLargerThan(MOBILE)
74-
ResponsiveBreakpoints.of(context).isSmallerThan(TABLET)
73+
ResponsiveBreakpoints.of(context).largerThan(MOBILE)
74+
ResponsiveBreakpoints.of(context).smallerThan(TABLET)
75+
...
7576
```
7677

7778
### Customization
@@ -91,7 +92,7 @@ breakpoints: [
9192

9293
Then, in our code, set the value based on the breakpoint condition.
9394

94-
> expand: ResponsiveBreakpoints.of(context).isLargerThan('EXPAND_SIDE_PANEL')
95+
> expand: ResponsiveBreakpoints.of(context).largerThan('EXPAND_SIDE_PANEL')
9596

9697
### Responsive Framework Widgets
9798
The ResponsiveFramework includes a few custom widgets that to supplement Flutter's responsive capabilities. They are showcased in the demo projects.

lib/responsive_breakpoints.dart

+34-4
Original file line numberDiff line numberDiff line change
@@ -332,22 +332,52 @@ class ResponsiveBreakpointsData {
332332
String toString() =>
333333
'ResponsiveWrapperData(breakpoint: $breakpoint, breakpoints: ${breakpoints.asMap()}, isMobile: $isMobile, isPhone: $isPhone, isTablet: $isTablet, isDesktop: $isDesktop)';
334334

335-
bool equals(String? name) => breakpoint.name == name;
335+
/// Returns if the active breakpoint is [name].
336+
bool equals(String name) => breakpoint.name == name;
336337

337-
/// Is the width larger than or equal to [name]?
338+
/// Is the [screenWidth] larger than [name]?
338339
/// Defaults to false if the [name] cannot be found.
339-
bool isLargerThan(String? name) =>
340+
bool largerThan(String name) =>
340341
screenWidth >
341342
(breakpoints.firstWhereOrNull((element) => element.name == name)?.end ??
342343
double.infinity);
343344

345+
/// Is the [screenWidth] larger than or equal to [name]?
346+
/// Defaults to false if the [name] cannot be found.
347+
bool largerOrEqualTo(String name) =>
348+
screenWidth >=
349+
(breakpoints.firstWhereOrNull((element) => element.name == name)?.start ??
350+
double.infinity);
351+
344352
/// Is the [screenWidth] smaller than the [name]?
345353
/// Defaults to false if the [name] cannot be found.
346-
bool isSmallerThan(String? name) =>
354+
bool smallerThan(String name) =>
347355
screenWidth <
348356
(breakpoints.firstWhereOrNull((element) => element.name == name)?.start ??
349357
0);
350358

359+
/// Is the [screenWidth] smaller than or equal to the [name]?
360+
/// Defaults to false if the [name] cannot be found.
361+
bool smallerOrEqualTo(String name) =>
362+
screenWidth <=
363+
(breakpoints.firstWhereOrNull((element) => element.name == name)?.end ??
364+
0);
365+
366+
/// Is the [screenWidth] smaller than or equal to the [name]?
367+
/// Defaults to false if the [name] cannot be found.
368+
bool between(String name, String name1) {
369+
return (screenWidth >=
370+
(breakpoints
371+
.firstWhereOrNull((element) => element.name == name)
372+
?.start ??
373+
0) &&
374+
screenWidth <=
375+
(breakpoints
376+
.firstWhereOrNull((element) => element.name == name1)
377+
?.end ??
378+
0));
379+
}
380+
351381
@override
352382
bool operator ==(Object other) =>
353383
identical(this, other) ||

lib/responsive_value.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class ResponsiveValue<T> {
100100

101101
if (condition.condition == Conditional.SMALLER_THAN) {
102102
if (condition.name != null) {
103-
if (responsiveWrapperData.isSmallerThan(condition.name!)) {
103+
if (responsiveWrapperData.smallerThan(condition.name!)) {
104104
return condition;
105105
}
106106
}
@@ -116,7 +116,7 @@ class ResponsiveValue<T> {
116116

117117
if (condition.condition == Conditional.LARGER_THAN) {
118118
if (condition.name != null) {
119-
if (responsiveWrapperData.isLargerThan(condition.name!)) {
119+
if (responsiveWrapperData.largerThan(condition.name!)) {
120120
return condition;
121121
}
122122
}

0 commit comments

Comments
 (0)