simulateLifecycleState method

Future<void> simulateLifecycleState(
  1. AppLifecycleState state
)

Simulate an AppLifecycleState change on any NyPage in the widget tree.

This triggers the didChangeAppLifecycleState callback, allowing you to test lifecycle actions defined in NyPage.lifecycleActions.

Example:

await tester.pumpNyWidget(MyPage());
await tester.simulateLifecycleState(AppLifecycleState.paused);
await tester.pump();
// Assert side effects of the paused lifecycle action

Implementation

Future<void> simulateLifecycleState(AppLifecycleState state) async {
  final ByteData? message = const StringCodec().encodeMessage(
    state.toString(),
  );
  await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
      .handlePlatformMessage('flutter/lifecycle', message, (_) {});
}