openFuture<T> static method

Widget openFuture<T>(
  1. Future<T> getFuture(),
  2. Future<PdfDocument> futureToDocument(
    1. T
    ), {
  3. Key? key,
  4. PdfViewerController? viewerController,
  5. PdfViewerParams? params,
  6. OnError? onError,
  7. Widget loadingBannerBuilder(
    1. BuildContext
    )?,
  8. PdfDocument? docFallback,
})

Open PDF using async function.

Implementation

static Widget openFuture<T>(
  Future<T> Function() getFuture,
  Future<PdfDocument> Function(T) futureToDocument, {
  Key? key,
  PdfViewerController? viewerController,
  PdfViewerParams? params,
  OnError? onError,
  Widget Function(BuildContext)? loadingBannerBuilder,
  PdfDocument? docFallback,
}) =>
    FutureBuilder<T>(
      key: key,
      future: getFuture(),
      builder: (context, snapshot) {
        final data = snapshot.data;
        if (data != null) {
          return PdfViewer(
            doc: futureToDocument(data),
            viewerController: viewerController,
            params: params,
            onError: onError,
          );
        } else if (loadingBannerBuilder != null) {
          return Builder(builder: loadingBannerBuilder);
        } else if (docFallback != null) {
          return PdfViewer(
            doc: Future.value(docFallback),
            viewerController: viewerController,
            params: params,
            onError: onError,
          );
        }
        return Container(); // ultimate fallback
      },
    );