flutter_cached_pdfview 0.1.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

flutter_cached_pdfview #

Pub Version GitHub repo size issues-raw license last-commit stars Dart CI


A package to show Native PDF View for iOS and Android, support Open from a different resource like Path, Asset or Url and Cache it.

Support = [ Android , IOS and WEB(soon) ]; #

  • Support Open Pdf From Path
  • Support Open Pdf From Asset
  • Support Open Pdf From URl and Cache it

Setup #

iOS

Opt-in to the embedded views preview by adding a boolean property to the app's Info.plist file with the key io.flutter.embedded_views_preview and the value YES.

iOS (only support> 11.0) you need to add this line in your ios/Podfile

platform :ios, '11.0'

ready-made in the Example

Import it #

Now in your Dart code, you can use:

import 'package:flutter_cached_pdfview/flutter_cached_pdfview.dart';

Options #

NameAndroidiOSDefault
defaultPage0
onViewCreatednull
onRendernull
onPageChangednull
onErrornull
onPageErrornull
gestureRecognizersnull
filePath
fitPolicyFitPolicy.WIDTH
enableSwipetrue
swipeHorizontalfalse
passwordnull
nightModefalse
passwordnull
autoSpacingtrue
pageFlingtrue
pageSnaptrue

Controller Options #

NameDescriptionParametersReturn
getPageCountGet total page count-Future<int>
getCurrentPageGet current page-Future<int>
setPageGo to/Set pageint pageFuture<bool>

Example #

from Asset

       PDF(
        enableSwipe: true,
        swipeHorizontal: true,
        autoSpacing: false,
        pageFling: false,
        onError: (error) {
          print(error.toString());
        },
        onPageError: (page, error) {
          print('$page: ${error.toString()}');
        },
        onPageChanged: (int page, int total) {
          print('page change: $page/$total');
        },
      ).fromAsset('assets/pdf/file-example.pdf'),

cached From Url

      PDF(
        swipeHorizontal: true,
      ).cachedFromUrl('http://africau.edu/images/default/sample.pdf'),

For production usage #

If you use proguard, you should include this line [ready-made in the Example].

-keep class com.shockwave.**

Dependencies #

Flutter #

flutter_pdfview

flutter_cache_manager

Android #

AndroidPdfViewer

iOS (only support> 11.0) #

PDFKit

Video #

IOS

WEB

Support #

Buy Me A Coffee

Donate with PayPal button
buy me a coffee by PayPal

Developer #

[0.1.7] - 2/07/2020. #

  • Test CI-CD

example/lib/main.dart

import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cached_pdfview/flutter_cached_pdfview.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('flutter_cached_pdfview Demo'),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          FlatButton(
            onPressed: () => Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => PDFViewerFromUrl(
                  url: 'http://africau.edu/images/default/sample.pdf',
                ),
              ),
            ),
            child: Text('Cashed PDF From Url'),
          ),
          FlatButton(
            onPressed: () => Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => PDFViewerFromAsset(
                  pdfAssetPath: 'assets/pdf/file-example.pdf',
                ),
              ),
            ),
            child: Text('PDF From Asset'),
          ),
        ],
      ),
    );
  }
}

class PDFViewerFromUrl extends StatelessWidget {
  final String url;

  const PDFViewerFromUrl({Key key, @required this.url}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('PDF From Url'),
      ),
      body: PDF(
        swipeHorizontal: true,
      ).cachedFromUrl(url),
    );
  }
}

class PDFViewerFromAsset extends StatelessWidget {
  PDFViewerFromAsset({Key key, @required this.pdfAssetPath}) : super(key: key);
  final String pdfAssetPath;
  final Completer<PDFViewController> _pdfViewController =
      Completer<PDFViewController>();
  final _pageCountController = StreamController<String>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('PDF From Asset'),
        actions: <Widget>[
          StreamBuilder<String>(
              stream: _pageCountController.stream,
              builder: (context, snapshot) {
                if (snapshot.hasData)
                  return Center(
                    child: Container(
                      padding: EdgeInsets.all(16),
                      decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        color: Colors.blue[900],
                      ),
                      child: Text(snapshot.data),
                    ),
                  );
                return SizedBox();
              }),
        ],
      ),
      body: PDF(
        enableSwipe: true,
        swipeHorizontal: true,
        autoSpacing: false,
        pageFling: false,
        onPageChanged: (current, total) =>
            _pageCountController.add('${current + 1} - $total'),
        onViewCreated: _pdfViewController.complete,
      ).fromAsset(pdfAssetPath),
      floatingActionButton: FutureBuilder<PDFViewController>(
        future: _pdfViewController.future,
        builder: (context, AsyncSnapshot<PDFViewController> snapshot) {
          if (snapshot.hasData) {
            return Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: <Widget>[
                FloatingActionButton(
                  heroTag: "-",
                  child: Text("-"),
                  onPressed: () async {
                    final pdfController = snapshot.data;
                    final currentPage =
                        await pdfController.getCurrentPage() - 1;
                    if (currentPage >= 0)
                      await snapshot.data.setPage(currentPage);
                  },
                ),
                FloatingActionButton(
                  heroTag: "+",
                  child: Text("+"),
                  onPressed: () async {
                    final pdfController = snapshot.data;
                    final currentPage =
                        await pdfController.getCurrentPage() + 1;
                    final numberOfPages = await pdfController.getPageCount();
                    if (numberOfPages > currentPage)
                      await snapshot.data.setPage(currentPage);
                  },
                ),
              ],
            );
          }
          return SizedBox();
        },
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_cached_pdfview: ^0.1.7

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_cached_pdfview/flutter_cached_pdfview.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
74
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
87
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform android

Because:

  • package:flutter_cached_pdfview/flutter_cached_pdfview.dart that imports:
  • package:flutter_cached_pdfview/src/pdf_view_types.dart that imports:
  • package:flutter_cached_pdfview/src/cached_pdf_view.dart that imports:
  • package:flutter_cache_manager/flutter_cache_manager.dart that imports:
  • package:flutter_cache_manager/src/cache_manager.dart that imports:
  • package:path_provider/path_provider.dart that imports:
  • package:path_provider_linux/path_provider_linux.dart that declares support for platforms: linux

Package does not support Flutter platform ios

Because:

  • package:flutter_cached_pdfview/flutter_cached_pdfview.dart that imports:
  • package:flutter_cached_pdfview/src/pdf_view_types.dart that imports:
  • package:flutter_cached_pdfview/src/cached_pdf_view.dart that imports:
  • package:flutter_cache_manager/flutter_cache_manager.dart that imports:
  • package:flutter_cache_manager/src/cache_manager.dart that imports:
  • package:path_provider/path_provider.dart that imports:
  • package:path_provider_linux/path_provider_linux.dart that declares support for platforms: linux

Package does not support Flutter platform linux

Because:

  • package:flutter_cached_pdfview/flutter_cached_pdfview.dart that imports:
  • package:flutter_pdfview/flutter_pdfview.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:flutter_cached_pdfview/flutter_cached_pdfview.dart that imports:
  • package:flutter_pdfview/flutter_pdfview.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:flutter_cached_pdfview/flutter_cached_pdfview.dart that imports:
  • package:flutter_pdfview/flutter_pdfview.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:flutter_cached_pdfview/flutter_cached_pdfview.dart that imports:
  • package:flutter_pdfview/flutter_pdfview.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • flutter_cached_pdfview that is a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

23 out of 23 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
flutter 0.0.0
flutter_cache_manager ^1.4.1 1.4.1
flutter_pdfview ^1.0.3 1.0.3
path_provider ^1.6.11 1.6.11
Transitive dependencies
charcode 1.1.3
clock 1.0.1
collection 1.14.12 1.14.13
convert 2.1.1
crypto 2.1.5
file 5.2.1
http 0.12.1
http_parser 3.1.4
intl 0.16.1
meta 1.1.8 1.2.2
path 1.7.0
path_provider_linux 0.0.1+2
path_provider_macos 0.0.4+3
path_provider_platform_interface 1.0.2
pedantic 1.9.0 1.9.2
platform 2.2.1
plugin_platform_interface 1.0.2
process 3.0.13
rxdart 0.24.1
sky_engine 0.0.99
source_span 1.7.0
sqflite 1.3.1
sqflite_common 1.0.2+1
string_scanner 1.0.5
synchronized 2.2.0+1
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
uuid 2.2.0
vector_math 2.0.8 2.1.0-nullsafety
xdg_directories 0.1.0
Dev dependencies
flutter_test