Search code examples
flutterpdfpdf-viewer

Flutter PDF Viewer shows only white pages


I'm trying to display a PDF file in Flutter which I have previously downloaded from a server. I have tried both flutter_full_pdf_viewer and advance_pdf_viewer. Both libs show me the correct number of pages, but the pages are all white.

Does anybody have an idea why? makes no difference if I run it on iOS or Android or in emulator or real device.

class _PdfPageState extends State<PdfPage> {

  String pathPDF = "";

  File file;
  PDFDocument doc = null;

  @override
  void initState() {
    super.initState();
    WeeklyReportsRepository( userRepository: UserRepository()).loadWeeklyReport(widget.weeklyReport.filename).then((file) {
        setDoc(file);
    });
  }

  Future<void> setDoc(File file) async {
    var doc1 = await PDFDocument.fromFile(file);
    setState(() {
      doc = doc1;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        iconTheme: IconThemeData(color: Colors.white),
        title: Text(
          "Wochenbericht",
          style: TextStyle(
            color: Colors.white,
          ),
        ),
      ),
      body: Container(
        color: Theme
            .of(context)
            .backgroundColor,
      child: (doc == null) ? Center(child: CircularProgressIndicator()) :
        PDFViewer(document: doc,
        scrollDirection: Axis.vertical,),
      ),
    );
  }
}

Solution

  • Everything seems right but can you try to view a pdf from your computer or a link and also try to view specific page of the pdf. Package document try load from assets, URL, or file as shown in the link if these ways work you have a problem from server side.