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

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: const Text("pdf_flutter demo"),
          ),
          body: PDFListBody(),
        ));
  }
}

class PDFListBody extends StatefulWidget {
  @override
  _PDFListBodyState createState() => _PDFListBodyState();
}

class _PDFListBodyState extends State<PDFListBody> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          RaisedButton(
            child: const Text("Pdf from asset"),
            onPressed: () {
              _navigateToPage(
                title: "Pdf from asset",
                child: PDF.asset(
                  "assets/pdf/demo.pdf",
                  placeHolder: Image.asset("assets/images/pdf.png",
                      height: 200, width: 100),
                ),
              );
            },
          ),
          RaisedButton(
            child: const Text("Pdf from network"),
            onPressed: () {
              _navigateToPage(
                title: "Pdf from networkUrl",
                child: PDF.network(
                  'https://google-developer-training.github.io/android-developer-fundamentals-course-concepts/en/android-developer-fundamentals-course-concepts-en.pdf',
                ),
              );
            },
          ),
          Builder(
            builder: (context) {
              return RaisedButton(
                child: const Text("PDF from file"),
                onPressed: () async {
                  final file = await FilePicker.platform.pickFiles(
                      allowedExtensions: ['pdf'], type: FileType.custom);
                  if (file?.files[0]?.path != null) {
                    _navigateToPage(
                      title: "PDF from file",
                      child: PDF.file(
                        File(file.files[0].path),
                      ),
                    );
                  } else {
                    Scaffold.of(context).showSnackBar(
                      const SnackBar(
                        content: Text("Failed to load Picked file"),
                      ),
                    );
                  }
                },
              );
            },
          )
        ],
      ),
    );
  }

  void _navigateToPage({String title, Widget child}) {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => Scaffold(
          appBar: AppBar(title: Text(title)),
          body: Center(child: child),
        ),
      ),
    );
  }
}
72
likes
40
pub points
85%
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

Apache-2.0 (license)

Dependencies

flutter, flutter_cache_manager, http, path_provider

More

Packages that depend on pdf_flutter