open static method
Future<PlaybookSession>
open({
- PlaybookClock? clock,
- bool overlay = true,
- PlaybookCaption caption = PlaybookCaption.bottom,
Starts a run: waits for the app's first frame and shows the overlay.
Every open needs a close. Use run unless you're running several playbooks back to back in one session.
Implementation
static Future<PlaybookSession> open({
PlaybookClock? clock,
bool overlay = true,
PlaybookCaption caption = PlaybookCaption.bottom,
}) async {
if (!isAvailable) {
throw UnsupportedError('Playbooks don\'t run in release builds.');
}
if (_active != null) {
throw StateError(
'A playbook is already running. Use play() to run one inside '
'another.',
);
}
final PlaybookClock time = clock ?? LivePlaybookClock();
final PlaybookOverlay? layer = overlay
? PlaybookOverlay(caption: caption)
: null;
final PlaybookSession session = PlaybookSession(
clock: time,
overlay: layer,
);
_active = session;
try {
// Pointer events are locked until the warm-up frame is done.
final Duration start = time.elapsed;
while (WidgetsBinding.instance.rootElement == null &&
time.elapsed - start < const Duration(seconds: 10)) {
await time.wait(const Duration(milliseconds: 50));
}
await time.frame();
if (layer != null && !layer.attach()) {
layer.detach();
return _active = PlaybookSession(clock: time);
}
await time.frame();
return session;
} catch (_) {
_active = null;
layer?.detach();
rethrow;
}
}