open method
void
open()
Installs attempt-local hooks. Calling this twice is an error.
Implementation
void open() {
if (_open) {
throw StateError('Attempt runtime scope is already open.');
}
_open = true;
_previousOnError = FlutterError.onError;
_previousRunner = LiveAsyncCallSupport.runner;
_previousPlatformHttpRunner = LiveAsyncCallSupport.platformHttpRunner;
_previousOverlayRunner = context.apiOverlay.liveAsyncRunner;
try {
_restoreDebugPrint = _captureDebugPrint();
FlutterError.onError = (details) {
context.runtime.flutterErrors.add(formatFlutterError(details));
};
Future<T?> runAppAsync<T>(Future<T> Function() callback) =>
tester.runAsync(
() => runWithRealNetworkHttpClient(
() => runZoned<Future<T>>(
callback,
zoneSpecification: context.runtime.consoleCaptureZone,
),
),
);
Future<T?> runPlatformHttpAsync<T>(Future<T> Function() callback) =>
tester.runAsync(
() => runWithRealNetworkHttpClient(callback),
);
context.apiOverlay.liveAsyncRunner = runAppAsync;
LiveAsyncCallSupport.runner = runAppAsync;
LiveAsyncCallSupport.platformHttpRunner = runPlatformHttpAsync;
} catch (error, stackTrace) {
try {
close();
} catch (_) {
// Keep the hook-installation failure primary. The attempt boundary
// reads closeFailures after this rollback and reports every restore
// failure as secondary evidence.
}
Error.throwWithStackTrace(error, stackTrace);
}
}