How to open a PDF in flutter [2021] No Errors!

anonymousprogrammer

Anonymous Programmer

Posted on June 25, 2021

How to open a PDF in flutter [2021] No Errors!

Hey Devs,
Today we are gonna open a PDF in our flutter project, I m creating this post cause I was struggling to add PDF in my project. Let's Get Started.

So you can create a file named pdf_page.dart or any file you want.

syncfusion_flutter_pdfviewer: ^19.1.69-beta

Add this in your pubspec.yaml I m using this version nd will recommed you to use the same.
I won't be wasting your time in making this in four steps, I hope you will understand code by yourself...

import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
import 'package:flutter/material.dart';

class PdfPath extends StatefulWidget {
  @override
  _PdfPathState createState() => _PdfPathState();
}

class _PdfPathState extends State<PdfPath> {
  final GlobalKey<SfPdfViewerState> _pdfViewerKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
            title: Text('Books'),
            backgroundColor: Colors.redAccent[400]),
        body: Padding(
          padding: const EdgeInsets.only(),
          child: Center(
            child: SingleChildScrollView(
              child: Center(
                child: Column(children: [
                  SfPdfViewer.network(
                    'http://www.africau.edu/images/default/sample.pdf',
                    key: _pdfViewerKey,
                  ),
                ]),
              ),
            ),
          ),
        ));
  }
}
Enter fullscreen mode Exit fullscreen mode

Hope It worked, If didn't please drop the error in comment section I will try my best to resolve your error :)
See you all in the other one

đź’– đź’Ş đź™… đźš©
anonymousprogrammer
Anonymous Programmer

Posted on June 25, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related