1

I am trying to add circularprogressindicator when my PDF is loading to show but I have no idea where to add it.

PDF API (where I am fetching the file to display from firebase)

import 'package:firebase_storage/firebase_storage.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';

import 'dart:io';

class PDFApi {
  static Future<File?> loadFirebase(String url) async {
    try {
      final refPDF = FirebaseStorage.instance.ref().child(url);
      final bytes = await refPDF.getData();

      return _storeFile(url, bytes!);
    } catch (e) {
      print('Please check your internet connection.');
    }
  }

  static Future<File> _storeFile(String url, List<int> bytes) async {
    final filename = basename(url);
    final dir = await getApplicationDocumentsDirectory();

    final file = File('${dir.path}/$filename');
    await file.writeAsBytes(bytes, flush: true);
    return file;
  }
}

PDF viewer page

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_pdfview/flutter_pdfview.dart';
import 'package:path/path.dart';

class PDFViewerPage extends StatefulWidget {
  final File file;

  const PDFViewerPage({
    Key? key,
    required this.file,
  }) : super(key: key);

  @override
  _PDFViewerPageState createState() => _PDFViewerPageState();
}

class _PDFViewerPageState extends State<PDFViewerPage> {
 
  @override
  Widget build(BuildContext context) {
    final name = basename(widget.file.path);

    return Scaffold(
      appBar: AppBar(
        title: Text(name),
      ),
      body: PDFView(
        pageSnap: false,
        pageFling: false,
        autoSpacing: false,
        filePath: widget.file.path,
      ),
    );
  }
}

and here's the button that triggers to show the PDF

onTap: () async {
                            final url = 'esei.pdf';
                            final file = await PDFApi.loadFirebase(url);
                            if (file == null) return;
                            openPDF(context, file);
                          },

I am currently still learning about dart and flutter, hope I can get some guidance from you guys. Thank you in advance!

ZXERSTON
  • 312
  • 4
  • 13
  • Does this answer your question? [What is a Future and how do I use it?](https://stackoverflow.com/questions/63017280/what-is-a-future-and-how-do-i-use-it) – nvoigt Oct 06 '21 at 06:09
  • I tried adding them to my code but, the circular and pdf is not even showing – ZXERSTON Oct 06 '21 at 11:19

0 Answers0