Skip to content

Instantly share code, notes, and snippets.

@VB10
Created June 5, 2021 22:59
Show Gist options
  • Save VB10/f5671bef0fa18ace683aba32abd8b708 to your computer and use it in GitHub Desktop.
Save VB10/f5671bef0fa18ace683aba32abd8b708 to your computer and use it in GitHub Desktop.
Future<Uint8List?> fetchData() async {
final data = await homeService.downloadFile(model.document ?? '');
return data;
}
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: buildFloatingActionButtonDownlaod(),
appBar: AppBar(title: Text(model.title ?? '')),
body: fetchData().toBuild<Uint8List?>(
onSuccess: (data) {
if (data != null) {
return PdfView(controller: PdfController(document: PdfDocument.openData(data)));
} else {
return buildErrorWidget();
}
},
loadingWidget: CircularProgressIndicator(),
notFoundWidget: buildErrorWidget(),
onError: buildErrorWidget()),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment