execute method
FutureOr<Step?>
execute(
- FlowContextController controller, [
- FutureOr<
Step?> candidate()?
override
Executes the builder function until an escape prompt is received.
Increases the FlowContext's depth and runs steps.
If closed the function will return it's given candidate or null.
Implementation
@override
FutureOr<Step?> execute(
final FlowContextController controller, [
FutureOr<Step?> candidate()?,
]) async {
controller.depth++;
final int initialDepth = controller.depth;
final none = () => null;
/*
* The [decide()] function will be the candidate for every [Step] of his
* builder. Therefore whenever the next Step should be returned, the [Bubble]
* will decide if it is still open and return the next [decide()] or the actual
* next "[candidate]" ([Step] in execution order).
*/
FutureOr<Step?> decide() async {
/*
* The [depth] of the controller will be able to change from the
* [Step]s the [Bubble] includes.
*/
if (initialDepth > controller.depth) {
return (candidate ?? none)();
}
/*
* In a derived class, leave can be set to leave the [Bubble] successfully.
* (Just without an error message)
*/
if (leave) {
controller.depth--;
return (candidate ?? none)();
}
return builder().execute(controller, decide);
}
return decide();
}