DEV Community

Anonymous Programmer
Anonymous Programmer

Posted on


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 {
  _PdfPathState createState() => _PdfPathState();

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

  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: [
                    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

Top comments (0)

Yes, this is technically an “ad”, but hear me out.

We have 900k+ developers reading, posting, and enjoying community, and would love to have you.

Create an account and continue your coding journey.