Control it from outside: LivenessController¶
You need this if you hide the built-in close button, want a Try again without leaving the screen, or need the state outside the widget.
final controller = LivenessController(); // create in initState, dispose in dispose
LivenessDetector(
controller: controller,
showCloseButton: false,
config: ...,
onResult: ...,
);
controller.cancel(); // onResult gets a cancelled result (cancelledBy: 'user')
await controller.restart(); // fresh session: new sessionId, new shuffle
controller.state; // live LivenessSessionState (it's a ChangeNotifier)
controller.actionPlan; // the actions in the order this session runs them
Every session still gets exactly one onResult: restarting a session
that's still running delivers it as cancelled with
cancelledBy: 'restart'. See the
controller recipe.