ensureScreenSize static method

Future<void> ensureScreenSize([
  1. FlutterView? window,
  2. Duration duration = const Duration(milliseconds: 10)
])

Implementation

static Future<void> ensureScreenSize([
  ui.FlutterView? window,
  Duration duration = const Duration(milliseconds: 10),
]) async {
  final binding = WidgetsFlutterBinding.ensureInitialized();
  binding.deferFirstFrame();

  await Future.doWhile(() {
    window ??= binding.platformDispatcher.implicitView;
    if (window == null || window!.physicalSize.isEmpty) {
      return Future.delayed(duration, () => true);
    }

    return false;
  });

  binding.allowFirstFrame();
}