Last active
December 13, 2022 12:04
-
-
Save Frankdroid7/24c5f0c4d8428d99764666013e89f223 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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