Advertisement
jevixlugya

pdf reader

Sep 22nd, 2024 (edited)
147
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.89 KB | None | 0 0
  1. import 'package:cloud_firestore/cloud_firestore.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
  4.  
  5.  
  6.  
  7. /// Represents Homepage for Navigation
  8. class ViewPdf extends StatefulWidget {
  9.    const ViewPdf({super.key});
  10.  
  11.   @override
  12.   State<ViewPdf> createState() => _ViewPdfState();
  13. }
  14.  
  15. class _ViewPdfState extends State<ViewPdf> {
  16.   final GlobalKey<SfPdfViewerState> _pdfViewerKey = GlobalKey();
  17.  
  18.   //getting pdf link from database
  19.   Future<String?> getlessonpdf() async {
  20.     try {
  21.       final DocumentSnapshot docRef = await FirebaseFirestore.instance
  22.           .collection("Lessonpdf")
  23.           .doc("adultquarterlesson")
  24.           .get();
  25.  
  26.       if (docRef.exists) {
  27.         final map = docRef.data() as Map<String, dynamic>;
  28.         String pdf = map['pdflink'];
  29.         //String profilepic=map['profilephoto'];
  30.  
  31.         return pdf;
  32.       } else {
  33.         print("document with id : \"adult lesson\" does not exists");
  34.  
  35.         return null;
  36.       }
  37.     } catch (e) {
  38.       print(e.toString());
  39.       rethrow;
  40.     }
  41.   }
  42.  
  43.   @override
  44.   Widget build(BuildContext context) {
  45.     return Scaffold(
  46.       appBar: AppBar(
  47.         title: const Text('ADULT LESSON' ,style:TextStyle(color: Colors.white,fontWeight: FontWeight.bold)),
  48.         backgroundColor: Colors.purple,
  49.         actions: <Widget>[
  50.           IconButton(
  51.             icon: const Icon(
  52.               Icons.bookmark,
  53.               color: Colors.white,
  54.               semanticLabel: 'Bookmark',
  55.             ),
  56.             onPressed: () {
  57.               _pdfViewerKey.currentState?.openBookmarkView();
  58.             },
  59.           ),
  60.         ],
  61.       ),
  62.       body: SfPdfViewer.network(
  63.             await getlessonpdf(),
  64.         //'https://www.adultbiblestudyguide.org/assets/public/files/lessons/2024/3Q/SE/PDFs/EAQ324_13.pdf',
  65.         key: _pdfViewerKey,
  66.       ),
  67.     );
  68.   }
  69. }
Advertisement
Comments
  • jevixlugya
    20 days
    # text 0.91 KB | 0 0
    1. solved
    2. class Example extends StatefulWidget {
    3. const Example({super.key});
    4.  
    5. @override
    6. State<Example> createState() => _ExampleState();
    7. }
    8. class _ExampleState extends State<Example> {
    9.  
    10. Future<String> getPdfURL() async {
    11. await Future.delayed(const Duration(seconds: 5));
    12.  
    13. return "http://example.com/pdf.pdf";
    14. }
    15.  
    16. @override
    17. Widget build(BuildContext context) {
    18. return Scaffold(
    19. body: FutureBuilder(
    20. future: getPdfURL(), // add your future method here
    21. builder: (context, snapshot) {
    22. if (snapshot.connectionState == ConnectionState.waiting) {
    23. return const CircularProgressIndicator();
    24. } else if (snapshot.hasError) {
    25. return Text('Error: ${snapshot.error}');
    26. } else {
    27. String url = snapshot.data!;
    28. return YourPDFViewerWidget(url: url);
    29. }
    30. },
    31. ),
    32. );
    33. }
    34. }
Add Comment
Please, Sign In to add comment
Advertisement