pdf_viewer_plugin 1.1.0 copy "pdf_viewer_plugin: ^1.1.0" to clipboard
pdf_viewer_plugin: ^1.1.0 copied to clipboard

outdated

A Flutter plugin for IOS and Android providing a simple way to display local file PDFs (enter to see some gifs).

Pdf Viewer Plugin #

pub package

A Flutter plugin for IOS and Android providing a simple way to display PDFs.

Features: #

  • Display PDF.

android ........... ios

Installation #

First, add pdf_viewer_plugin as a dependency in your pubspec.yaml file.

iOS #

Add one row to the ios/Runner/info.plist:

...

<key>io.flutter.embedded_views_preview</key>
<true/>

You need to

Example #

Here is an example flutter app.

import 'dart:async';
import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:pdf_viewer_plugin/pdf_viewer_plugin.dart';
import 'package:path_provider/path_provider.dart';
import 'package:http/http.dart' as http;

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String path;

  @override
  initState() {
    super.initState();
  }

  Future<String> get _localPath async {
    final directory = await getApplicationDocumentsDirectory();

    return directory.path;
  }

  Future<File> get _localFile async {
    final path = await _localPath;
    return File('$path/teste.pdf');
  }

  Future<File> writeCounter(Uint8List stream) async {
    final file = await _localFile;

    // Write the file
    return file.writeAsBytes(stream);
  }

  Future<Uint8List> fetchPost() async {
    final response = await http.get(
        'https://expoforest.com.br/wp-content/uploads/2017/05/exemplo.pdf');
    final responseJson = response.bodyBytes;

    return responseJson;
  }

  loadPdf() async {
    writeCounter(await fetchPost());
    path = (await _localFile).path;

    if (!mounted) return;

    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              if (path != null)
                Container(
                  height: 300.0,
                  child: PdfViewer(
                    filePath: path,
                  ),
                )
              else
                Text("Pdf is not Loaded"),
              RaisedButton(
                child: Text("Load pdf"),
                onPressed: loadPdf,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Feedback welcome and Pull Requests are most welcome!

69
likes
0
pub points
96%
popularity

Publisher

verified publisherbritto.dev

A Flutter plugin for IOS and Android providing a simple way to display local file PDFs (enter to see some gifs).

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on pdf_viewer_plugin