lazyWidget static method

Widget lazyWidget(
  1. Future<Widget> builder(), {
  2. Widget? placeholder,
})

Implementation

static Widget lazyWidget(Future<Widget> Function() builder,
    {Widget? placeholder}) {
  return FutureBuilder<Widget>(
    future: builder(),
    builder: (ctx, snapshot) {
      if (snapshot.connectionState == ConnectionState.waiting) {
        return placeholder ??
            const Center(child: CircularProgressIndicator());
      }
      if (snapshot.hasError) {
        return Center(child: Text('Error: ${snapshot.error}'));
      }
      if (snapshot.hasData) {
        return snapshot.data!;
      }
      return placeholder ?? const SizedBox.shrink();
    },
  );
}