preconditions library


PreconditionsRepository creates this object from PreconditionFunction which you register in PreconditionsRepository.registerPrecondition(). Think of it as a handle to your precondition. It is a mutable ChangeNotifier, but is modified only through methods of PreconditionsRepository and from your point of view is read-only. It's possible to integrate it with your state management tool, for example:
Unique identificator of precondition.
Repository of all preconditions of your app. You will typically need just one singleton instance of PreconditionsRepository. It is a mutable ChangeNotifier, which you can integrate with all sort of state management tools.
Result of precondition check. Your precondition function should return one of two possible results:


forEver → const Duration
Use this constant to specify unlimited cache in PreconditionsRepository.registerPrecondition


lazy(PreconditionId targetId) → _Dependency
The dependant will be satisfied only if the target is satisfied during the evaluation. However - later fails or crashes of target will NOT change the status of the dependant. The status will remain unchanged untill the evaluation of the dependant.
oneTime(PreconditionId targetId) → _Dependency
This kind of dependency requires the target to be satisfied at least once. Later fails or crashes of the target doesn't change the dependants status.
tight(PreconditionId targetId) → _Dependency
The dependant will never be satisfied unless the target is satisfied as well. Later fails or crashes will immediately propagate to the dependant, even when the dependant is not being evaluated.


InitPreconditionFunction = FutureOr Function()
PreconditionFunction = FutureOr<PreconditionStatus> Function()
Implement your precondition verification in form of this function type. Return either: PreconditionStatus.satisfied() or PreconditionStatus.Failed() as a result of your test.