valueFromConditionByBreakpoints<T> function
T?
valueFromConditionByBreakpoints<T>({
- required BuildContext context,
- required List<
ConditionBreakpoint< condition,T> > - ScreenBreakpoints? localBreakpoints,
- T? defaultValue,
The goal is to get the actual value for a list of conditions
.
context
it is BuildContext
of the app or the widget.
localBreakpoints
are the local breakpoints for the widget.
condition
The list of conditions to evaluate.
defaultValue
Default value in case your list of conditions
doesn't return anything.
The priority of this method is to calculate the value of the conditions,
the priority will be EQUALS
, SMALLER_THAN
, LARGER_THAN
For the ConditionBreakpoint where breakpoint
was null and
the values were send like a DeviceScreen the breakpoint
will be change between
localBreakpoints
, GlobalBreakpoints
or DefaultBreakpoints
using getCurrentBreakPoints
Implementation
T? valueFromConditionByBreakpoints<T>({
required BuildContext context,
required List<ConditionBreakpoint<T>> condition,
ScreenBreakpoints? localBreakpoints,
T? defaultValue,
}) {
final nCondition = List<ConditionBreakpoint<T>>.from(condition);
nCondition.removeWhere((element) => element.isNull);
final rw = ResponsiveWrapper.getWrapperConfig(context);
final breakpoints = getCurrentBreakPoints(
global: rw.globalBreakpoints,
local: localBreakpoints,
);
final valueWhen = _setDefaultValuesToConditions<T>(
breakpoints,
nCondition,
);
valueWhen.sort((a, b) => a.breakpoint!.compareTo(b.breakpoint!));
final activeCondition = _getActiveCondition<T>(
context,
rw,
valueWhen,
breakpoints,
);
return activeCondition?.value ?? defaultValue;
}