sleep static method

Future<void> sleep(
  1. Duration duration
)

Calls thread sleep on the native layer. Useful for testing ANR reporting.

Method might throw exception.

try {
  await Instrumentation.sleep(5000);
} catch (e) {
  // handle exception
}

Implementation

static Future<void> sleep(Duration duration) async {
  try {
    final args = {"seconds": duration.inSeconds};
    await channel.invokeMethod<void>('sleep', args);
  } on PlatformException catch (e) {
    throw Exception(e.details);
  }
}