Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:cloud_firestore/cloud_firestore.dart';
- import 'package:flutter/material.dart';
- import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
- /// Represents Homepage for Navigation
- class ViewPdf extends StatefulWidget {
- const ViewPdf({super.key});
- @override
- State<ViewPdf> createState() => _ViewPdfState();
- }
- class _ViewPdfState extends State<ViewPdf> {
- final GlobalKey<SfPdfViewerState> _pdfViewerKey = GlobalKey();
- //getting pdf link from database
- Future<String?> getlessonpdf() async {
- try {
- final DocumentSnapshot docRef = await FirebaseFirestore.instance
- .collection("Lessonpdf")
- .doc("adultquarterlesson")
- .get();
- if (docRef.exists) {
- final map = docRef.data() as Map<String, dynamic>;
- String pdf = map['pdflink'];
- //String profilepic=map['profilephoto'];
- return pdf;
- } else {
- print("document with id : \"adult lesson\" does not exists");
- return null;
- }
- } catch (e) {
- print(e.toString());
- rethrow;
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: const Text('ADULT LESSON' ,style:TextStyle(color: Colors.white,fontWeight: FontWeight.bold)),
- backgroundColor: Colors.purple,
- actions: <Widget>[
- IconButton(
- icon: const Icon(
- Icons.bookmark,
- color: Colors.white,
- semanticLabel: 'Bookmark',
- ),
- onPressed: () {
- _pdfViewerKey.currentState?.openBookmarkView();
- },
- ),
- ],
- ),
- body: SfPdfViewer.network(
- await getlessonpdf(),
- //'https://www.adultbiblestudyguide.org/assets/public/files/lessons/2024/3Q/SE/PDFs/EAQ324_13.pdf',
- key: _pdfViewerKey,
- ),
- );
- }
- }
Advertisement
Comments
-
- solved
- class Example extends StatefulWidget {
- const Example({super.key});
- @override
- State<Example> createState() => _ExampleState();
- }
- class _ExampleState extends State<Example> {
- Future<String> getPdfURL() async {
- await Future.delayed(const Duration(seconds: 5));
- return "http://example.com/pdf.pdf";
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: FutureBuilder(
- future: getPdfURL(), // add your future method here
- builder: (context, snapshot) {
- if (snapshot.connectionState == ConnectionState.waiting) {
- return const CircularProgressIndicator();
- } else if (snapshot.hasError) {
- return Text('Error: ${snapshot.error}');
- } else {
- String url = snapshot.data!;
- return YourPDFViewerWidget(url: url);
- }
- },
- ),
- );
- }
- }
Add Comment
Please, Sign In to add comment
Advertisement