visit method
Opens the page at path, passing data to it.
Implementation
Future<void> visit(String path, {Object? data}) async {
Object? error;
if (_nyloRouter) {
// A push only completes when the page is popped, so it isn't awaited.
unawaited(
routeTo(path, data: data).then(
(_) {},
onError: (Object e) {
error = e;
},
),
);
} else {
final NavigatorState? navigator = _navigator();
if (navigator == null) {
throw const PlaybookFailure('The app has no navigator to visit with.');
}
unawaited(
navigator
.pushNamed(path, arguments: data)
.then(
(_) {},
onError: (Object e) {
error = e;
},
),
);
}
final Duration start = _clock.elapsed;
while (currentRouteName() != path) {
_checkStopped();
if (error != null) {
throw PlaybookFailure('Could not open $path: $error');
}
if (_clock.elapsed - start >= timeout) {
throw PlaybookFailure(
'Visited $path, but the app is on '
'${currentRouteName() ?? 'an unnamed page'}.',
);
}
await _sleep(_poll);
}
await _settle(navigated: true);
}