when method
- @Deprecated('Use `context.select` or `UseCompute` instead. ' 'This feature was deprecated after v6.1.0.pre.')
- dynamic condition(), [
- dynamic condition2()?,
- dynamic condition3()?,
- dynamic condition4()?,
- dynamic condition5()?,
Takes multiple conditions and returns a list of UseCompute based on theses conditions.
Generally, it's used to listen for conditional states using context.watch
:
context.watch<AppController>(
(inst) => [inst.stateA, inst.stateB].when(
() => inst.stateA.value == inst.stateB.value, // condition
// The following condition functions as `or` like:
// condition || condition2 || condition3
() => inst.stateA.value == 'X', // condition2
() => inst.stateB.value == 'Y', // condition3
),
);
Use UseCompute instead to improve performance, creating it out of context.
Implementation
@Deprecated(
'Use `context.select` or `UseCompute` instead. '
'This feature was deprecated after v6.1.0.pre.',
)
List<UseCompute> when(
dynamic Function() condition, [
dynamic Function()? condition2,
dynamic Function()? condition3,
dynamic Function()? condition4,
dynamic Function()? condition5,
]) {
return [condition, condition2, condition3, condition4, condition5]
.whereType<dynamic Function()>()
.map((condition) => UseWhen(condition, this))
.toList();
}