getActiveCondition method
Set activeCondition
.
The active condition is found by matching the
search criteria in order of precedence:
- Conditional.EQUALS Named breakpoints from a parent ResponsiveWrapper.
- Conditional.SMALLER_THAN a. Named breakpoints. b. Unnamed breakpoints.
- Conditional.LARGER_THAN a. Named breakpoints. b. Unnamed breakpoints. Returns null if no Active Condition is found.
Implementation
Condition? getActiveCondition(
BuildContext context, List<Condition> conditions) {
Condition? equalsCondition = conditions.firstWhereOrNull((element) {
if (element.condition == Conditional.EQUALS) {
return ResponsiveWrapper.of(context).activeBreakpoint.name ==
element.name;
}
return false;
});
if (equalsCondition != null) {
return equalsCondition;
}
Condition? smallerThanCondition = conditions.firstWhereOrNull((element) {
if (element.condition == Conditional.SMALLER_THAN) {
if (element.name != null) {
return ResponsiveWrapper.of(context).isSmallerThan(element.name!);
}
return MediaQuery.of(context).size.width < element.breakpoint!;
}
return false;
});
if (smallerThanCondition != null) {
return smallerThanCondition;
}
Condition? largerThanCondition =
conditions.reversed.firstWhereOrNull((element) {
if (element.condition == Conditional.LARGER_THAN) {
if (element.name != null) {
return ResponsiveWrapper.of(context).isLargerThan(element.name);
}
return MediaQuery.of(context).size.width >= element.breakpoint!;
}
return false;
});
if (largerThanCondition != null) {
return largerThanCondition;
}
return null;
}