DeferInit<T extends Widget?> constructor

const DeferInit<T extends Widget?>({
  1. Key? key,
  2. required OnDeferInit<T> onDefer,
  3. Widget loadingWidget = const SizedBox.shrink(),
  4. Widget emptyWidget = const SizedBox.shrink(),
})

Prevents the initialization of UI until the provided asynchronous task is completed.

This is done by using the deferFirstFrame() and allowFirstFrame() functions from Flutter's RendererBinding mixin.

Use in a StatefulWidget when async initialization of a service class is required before initState starts to build UI.

This widget was created by Simon Lightfoot and modified slightly by GroovinChip. Please view the original source here

Implementation

const DeferInit({
  super.key,
  required this.onDefer,
  this.loadingWidget = const SizedBox.shrink(),
  this.emptyWidget = const SizedBox.shrink(),
});