mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2026-08-24 16:50:47 +00:00
Convert 17 multi-file apps to the validated pattern: lib/main.dart keeps only the MaterialApp bootstrap; a new lib/example.dart holds the full entry screen and focused example code, importing existing supporting files (screens/, tabs/, services/, models/, widgets/, utils/). Apps: analytics_integration, animation_example, biometrics, bottom_sheet, custom_home_drawer, google_signin, grid_layout, handling_routes, image_editor, scan_qr_code, statless_counter_app, using_bottom_nav_bar, using_custom_fonts, using_listview, using_listwheelscrollview, using_platform_adaptive, view_pdf_file
85 lines
2.1 KiB
Dart
85 lines
2.1 KiB
Dart
// Example: View PDF file
|
|
import 'package:flutter/material.dart';
|
|
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
|
import 'package:view_pdf_file/constants.dart';
|
|
import 'package:view_pdf_file/viewPDF.dart';
|
|
|
|
class Example extends StatefulWidget {
|
|
const Example({super.key});
|
|
|
|
@override
|
|
ExampleState createState() => ExampleState();
|
|
}
|
|
|
|
class ExampleState extends State<Example> {
|
|
bool isLoading = false;
|
|
late Widget pdfViewer;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text("View PDF File"),
|
|
),
|
|
body: Container(
|
|
child: Center(
|
|
child: isLoading
|
|
? CircularProgressIndicator()
|
|
: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.max,
|
|
children: [
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
loadFromAsset();
|
|
},
|
|
child: Text("Load local PDF"),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
loadFromURL();
|
|
},
|
|
child: Text("Load PDF via URL"),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> loadFromAsset() async {
|
|
setState(() {
|
|
isLoading = true;
|
|
});
|
|
pdfViewer = SfPdfViewer.asset('assets/Hello.pdf');
|
|
setState(() {
|
|
isLoading = false;
|
|
});
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => ViewPDF(viewer: pdfViewer),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> loadFromURL() async {
|
|
setState(() {
|
|
isLoading = true;
|
|
});
|
|
|
|
pdfViewer = SfPdfViewer.network(Constants.pdfURL);
|
|
setState(() {
|
|
isLoading = false;
|
|
});
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => ViewPDF(viewer: pdfViewer),
|
|
),
|
|
);
|
|
}
|
|
}
|