pdf_flutter 1.1.1 copy "pdf_flutter: ^1.1.1" to clipboard
pdf_flutter: ^1.1.1 copied to clipboard

outdated

Displaying PDF from Network, File and assets easily like we display Image in Flutter Widget.

example/lib/main.dart

import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:pdf_flutter/pdf_flutter.dart';

void main() => runApp(PdfApp());

class PdfApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        home: Scaffold(
          appBar: AppBar(
            title: Text("pdf_flutter demo"),
          ),
          body: PDFListBody(),
        ));
  }
}

class PDFListBody extends StatefulWidget {
  const PDFListBody({
    Key key,
  }) : super(key: key);

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

class _PDFListBodyState extends State<PDFListBody> {
  File localFile;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Row(
          children: <Widget>[
            Column(
              children: <Widget>[
                Text("PDF.network(url)"),
                PDF.network(
                  'https://google-developer-training.github.io/android-developer-fundamentals-course-concepts/en/android-developer-fundamentals-course-concepts-en.pdf',
                  height: 300,
                  width: 200,
                  placeHolder: Image.asset("assets/images/pdf.png",
                      height: 200, width: 100),
                ),
              ],
            ),
            SizedBox(
              height: 10,
            ),
            Column(
              children: <Widget>[
                Text("PDF.assets(assetname)"),
                PDF.assets(
                  "assets/pdf/demo.pdf",
                  height: 300,
                  width: 200,
                  placeHolder: Image.asset("assets/images/pdf.png",
                      height: 200, width: 100),
                ),
              ],
            ),
          ],
        ),
        SizedBox(
          height: 10,
        ),
        localFile != null
            ? Column(
                children: <Widget>[
                  Text("PDF.file(fileName)"),
                  PDF.file(
                    localFile,
                    height: 300,
                    width: 200,
                    placeHolder: Image.asset("assets/images/pdf.png",
                        height: 200, width: 100),
                  ),
                ],
              )
            : InkWell(
                onTap: () async {
                  File file = await FilePicker.getFile(
                      allowedExtensions: ['pdf'], type: FileType.custom);
                  setState(() {
                    localFile = file;
                  });
                },
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Container(
                    height: 300,
                    decoration: BoxDecoration(
                      color: Colors.cyan,
                      borderRadius: BorderRadius.circular(20),
                    ),
                    child: Center(
                      child: Text(
                        "Select PDF from device",
                        textAlign: TextAlign.center,
                        style: TextStyle(fontSize: 45, color: Colors.white),
                      ),
                    ),
                  ),
                ),
              )
      ],
    );
  }
}
72
likes
0
pub points
88%
popularity

Publisher

verified publishererluxman.com

Displaying PDF from Network, File and assets easily like we display Image in Flutter Widget.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, flutter_cache_manager, http, path_provider, pedantic, uuid

More

Packages that depend on pdf_flutter