Skip to content

Instantly share code, notes, and snippets.

@Frankdroid7
Last active December 13, 2022 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Frankdroid7/24c5f0c4d8428d99764666013e89f223 to your computer and use it in GitHub Desktop.
Save Frankdroid7/24c5f0c4d8428d99764666013e89f223 to your computer and use it in GitHub Desktop.
class PdfView extends StatefulWidget {
const PdfView({Key? key}) : super(key: key);
@override
State<PdfView> createState() => _PdfViewState();
}
class _PdfViewState extends State<PdfView> {
String? pdfPath;
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
getPdfBytesFromUrl(
'https://www.vuemastery.com/pdf/Vue-Essentials-Cheat-Sheet.pdf')
.then((bytes) {
storeAndSharePdf(bytes);
});
},
child: const Text('Get PDF'),
),
const SizedBox(width: 10),
ElevatedButton(
onPressed: () {
if (pdfPath != null) {
sharePdfFile(pdfPath!);
}
},
child: const Text('Share PDF'),
),
],
),
pdfPath != null
? Expanded(
child: PDFView(
filePath: pdfPath,
autoSpacing: false,
onError: (error) {
print(error.toString());
},
onPageError: (page, error) {
print('$page: ${error.toString()}');
},
),
)
: const SizedBox.shrink(),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment