void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'PDF Viewer',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: PdfViewerScreen(
pdfUrl:
'https://example.com/pdf/sample.pdf'), // Replace with your PDF URL
);
}
}
Note that this implementation uses the PDFViewer.openAsset() method, which expects the PDF file to be available as an asset in your project. You can replace it with PDFViewer.loadNetwork() or other methods depending on your use case.
Make sure to replace the pdfUrl with your desired PDF URL or asset name.
Remember to include the necessary permissions to access the internet if you're loading a PDF from a network location by modifying your AndroidManifest.xml file:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'PDF Viewer',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: PdfViewerScreen(
pdfUrl:
'https://example.com/pdf/sample.pdf'), // Replace with your PDF URL
);
}
}
Make sure to replace the pdfUrl with your desired PDF URL.
Please note that the pdf_viewer_web package uses the <webview> HTML element to render the PDF, so it will only work on web platforms and not on Android or iOS.
Make sure to enable Flutter for web by running flutter config --enable-web in your terminal before you can run your Flutter web app.
This implementation will display a PDF viewer with the specified PDF file URL.