From 6e60782af7281383a4fd9ccf71fc9f86eb4ae50a Mon Sep 17 00:00:00 2001 From: Wendell Farley Date: Thu, 12 Dec 2019 15:48:26 -0600 Subject: [PATCH 01/34] cleanup cache and fix temp file name current always results in .pdf as prefix --- .../FlutterPluginPdfViewerPlugin.java | 94 ++++++++++++------- 1 file changed, 61 insertions(+), 33 deletions(-) diff --git a/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java b/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java index ffe19f3c..cfd26c7f 100644 --- a/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java +++ b/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java @@ -10,6 +10,7 @@ import java.io.File; import java.io.FileOutputStream; +import java.io.FilenameFilter; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; @@ -42,7 +43,7 @@ public static void registerWith(Registrar registrar) { @Override public void onMethodCall(final MethodCall call, final Result result) { - synchronized(pluginLocker){ + synchronized (pluginLocker) { if (backgroundHandler == null) { handlerThread = new HandlerThread("flutterPdfViewer", Process.THREAD_PRIORITY_BACKGROUND); handlerThread.start(); @@ -50,41 +51,41 @@ public void onMethodCall(final MethodCall call, final Result result) { } } final Handler mainThreadHandler = new Handler(); - backgroundHandler.post( - new Runnable() { - @Override - public void run() { - switch (call.method) { - case "getNumberOfPages": - final String numResult = getNumberOfPages((String) call.argument("filePath")); - mainThreadHandler.post(new Runnable(){ - @Override - public void run() { - result.success(numResult); - } - }); - break; - case "getPage": - final String pageResult = getPage((String) call.argument("filePath"), (int) call.argument("pageNumber")); - mainThreadHandler.post(new Runnable(){ - @Override - public void run() { - result.success(pageResult); - } - }); - break; - default: - result.notImplemented(); - break; + backgroundHandler.post(new Runnable() { + @Override + public void run() { + switch (call.method) { + case "getNumberOfPages": + final String numResult = getNumberOfPages((String) call.argument("filePath")); + mainThreadHandler.post(new Runnable() { + @Override + public void run() { + result.success(numResult); } - } + }); + break; + case "getPage": + final String pageResult = getPage((String) call.argument("filePath"), + (int) call.argument("pageNumber")); + mainThreadHandler.post(new Runnable() { + @Override + public void run() { + result.success(pageResult); + } + }); + break; + default: + result.notImplemented(); + break; } - ); + } + }); } private String getNumberOfPages(String filePath) { File pdf = new File(filePath); try { + clearCacheDir(filePath); PdfRenderer renderer = new PdfRenderer(ParcelFileDescriptor.open(pdf, ParcelFileDescriptor.MODE_READ_ONLY)); Bitmap bitmap; final int pageCount = renderer.getPageCount(); @@ -95,12 +96,40 @@ private String getNumberOfPages(String filePath) { return null; } - private String createTempPreview(Bitmap bmp, String name, int page) { + private boolean clearCacheDir(String filePath) { + try { + File directory = instance.context().getCacheDir(); + final String searchName = getFileNameFromPath(filePath); + FilenameFilter myFilter = new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.toLowerCase().startsWith(searchName); + } + }; + File[] files = directory.listFiles(myFilter); + // Log.d("Cache Files", "Size: " + files.length); + for (int i = 0; i < files.length; i++) { + // Log.d("Files", "FileName: " + files[i].getName()); + files[i].delete(); + } + return true; + } catch (Exception ex) { + ex.printStackTrace(); + return false; + } + } + + private String getFileNameFromPath(String name) { String filePath = name.substring(name.lastIndexOf('/') + 1); - filePath = name.substring(name.lastIndexOf('.')); + filePath = filePath.substring(0, filePath.lastIndexOf('.')); + return filePath; + } + + private String createTempPreview(Bitmap bmp, String name, int page) { + String fileNameOnly = getFileNameFromPath(name); File file; try { - String fileName = String.format("%s-%d.png", filePath, page); + String fileName = String.format("%s-%d.png", fileNameOnly, page); file = File.createTempFile(fileName, null, instance.context().getCacheDir()); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 100, out); @@ -113,7 +142,6 @@ private String createTempPreview(Bitmap bmp, String name, int page) { return file.getAbsolutePath(); } - private String getPage(String filePath, int pageNumber) { File pdf = new File(filePath); try { From aac8822f85fa6c07cfd821e87f593be5885513a1 Mon Sep 17 00:00:00 2001 From: Wendell Farley Date: Thu, 12 Dec 2019 15:48:44 -0600 Subject: [PATCH 02/34] cleanup cache and fix temp file name current always results in .pdf as prefix --- android/.settings/org.eclipse.buildship.core.prefs | 11 +++++++++++ .../.settings/org.eclipse.buildship.core.prefs | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/android/.settings/org.eclipse.buildship.core.prefs b/android/.settings/org.eclipse.buildship.core.prefs index e8895216..5628deb6 100644 --- a/android/.settings/org.eclipse.buildship.core.prefs +++ b/android/.settings/org.eclipse.buildship.core.prefs @@ -1,2 +1,13 @@ +arguments=--scan +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0-20191016123526+0000)) connection.project.dir= eclipse.preferences.version=1 +gradle.user.home= +java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home +jvm.arguments= +offline.mode=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true diff --git a/example/android/.settings/org.eclipse.buildship.core.prefs b/example/android/.settings/org.eclipse.buildship.core.prefs index 7338097b..5628deb6 100644 --- a/example/android/.settings/org.eclipse.buildship.core.prefs +++ b/example/android/.settings/org.eclipse.buildship.core.prefs @@ -1,11 +1,11 @@ -arguments= +arguments=--scan auto.sync=false build.scans.enabled=false -connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(5.4)) +connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0-20191016123526+0000)) connection.project.dir= eclipse.preferences.version=1 gradle.user.home= -java.home= +java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home jvm.arguments= offline.mode=false override.workspace.settings=true From 80a99f79f83a3e68db2bb386adfa0f2cbe0aea0c Mon Sep 17 00:00:00 2001 From: Wendell Farley Date: Thu, 12 Dec 2019 15:52:43 -0600 Subject: [PATCH 03/34] fixed spacing --- .../FlutterPluginPdfViewerPlugin.java | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java b/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java index cfd26c7f..abf52966 100644 --- a/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java +++ b/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java @@ -51,35 +51,36 @@ public void onMethodCall(final MethodCall call, final Result result) { } } final Handler mainThreadHandler = new Handler(); - backgroundHandler.post(new Runnable() { - @Override - public void run() { - switch (call.method) { - case "getNumberOfPages": - final String numResult = getNumberOfPages((String) call.argument("filePath")); - mainThreadHandler.post(new Runnable() { - @Override - public void run() { - result.success(numResult); + backgroundHandler.post(// + new Runnable() { + @Override + public void run() { + switch (call.method) { + case "getNumberOfPages": + final String numResult = getNumberOfPages((String) call.argument("filePath")); + mainThreadHandler.post(new Runnable() { + @Override + public void run() { + result.success(numResult); + } + }); + break; + case "getPage": + final String pageResult = getPage((String) call.argument("filePath"), + (int) call.argument("pageNumber")); + mainThreadHandler.post(new Runnable() { + @Override + public void run() { + result.success(pageResult); + } + }); + break; + default: + result.notImplemented(); + break; } - }); - break; - case "getPage": - final String pageResult = getPage((String) call.argument("filePath"), - (int) call.argument("pageNumber")); - mainThreadHandler.post(new Runnable() { - @Override - public void run() { - result.success(pageResult); - } - }); - break; - default: - result.notImplemented(); - break; - } - } - }); + } + }); } private String getNumberOfPages(String filePath) { From 159dd8f8e6009d8245d4fbcd3b288b0cd62711d6 Mon Sep 17 00:00:00 2001 From: Wendell Farley Date: Thu, 12 Dec 2019 16:11:25 -0600 Subject: [PATCH 04/34] rxdart version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 3b97efdd..ac21462a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: sdk: flutter flutter_cache_manager: ^1.0.0 path_provider: ^1.1.0 - rxdart: ^0.21.0 + rxdart: ^0.22.0 numberpicker: ^1.0.0 flutter_advanced_networkimage: ^0.5.0 From 2596f737300f07905ab6cba8b5112cf410a5966b Mon Sep 17 00:00:00 2001 From: Wendell Farley Date: Fri, 13 Dec 2019 17:31:26 -0600 Subject: [PATCH 05/34] add prefix so cache cleanup works better to have only 1 pdf cached at a time --- .../FlutterPluginPdfViewerPlugin.java | 10 +++++----- pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java b/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java index abf52966..3a0af79c 100644 --- a/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java +++ b/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java @@ -31,6 +31,7 @@ public class FlutterPluginPdfViewerPlugin implements MethodCallHandler { private HandlerThread handlerThread; private Handler backgroundHandler; private final Object pluginLocker = new Object(); + private final String filePrefix = "FlutterPluginPdfViewer"; /** * Plugin registration. @@ -86,7 +87,7 @@ public void run() { private String getNumberOfPages(String filePath) { File pdf = new File(filePath); try { - clearCacheDir(filePath); + clearCacheDir(); PdfRenderer renderer = new PdfRenderer(ParcelFileDescriptor.open(pdf, ParcelFileDescriptor.MODE_READ_ONLY)); Bitmap bitmap; final int pageCount = renderer.getPageCount(); @@ -97,14 +98,13 @@ private String getNumberOfPages(String filePath) { return null; } - private boolean clearCacheDir(String filePath) { + private boolean clearCacheDir() { try { File directory = instance.context().getCacheDir(); - final String searchName = getFileNameFromPath(filePath); FilenameFilter myFilter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { - return name.toLowerCase().startsWith(searchName); + return name.toLowerCase().startsWith(filePrefix); } }; File[] files = directory.listFiles(myFilter); @@ -123,7 +123,7 @@ public boolean accept(File dir, String name) { private String getFileNameFromPath(String name) { String filePath = name.substring(name.lastIndexOf('/') + 1); filePath = filePath.substring(0, filePath.lastIndexOf('.')); - return filePath; + return String.format("%s-%s", filePrefix, filePath); } private String createTempPreview(Bitmap bmp, String name, int page) { diff --git a/pubspec.yaml b/pubspec.yaml index ac21462a..60194b73 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_plugin_pdf_viewer description: A flutter plugin for handling PDF files. Works on both Android & iOS -version: 1.0.7 +version: 1.0.8 author: Tiago Ribeiro homepage: https://github.com/CrossPT/flutter_plugin_pdf_viewer From 6cfbe43d8b0349cd0be73dfc518995c17823e719 Mon Sep 17 00:00:00 2001 From: Wendell Farley Date: Mon, 16 Dec 2019 08:57:49 -0600 Subject: [PATCH 06/34] lower case check --- .../flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java b/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java index 3a0af79c..9c230013 100644 --- a/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java +++ b/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java @@ -104,7 +104,7 @@ private boolean clearCacheDir() { FilenameFilter myFilter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { - return name.toLowerCase().startsWith(filePrefix); + return name.toLowerCase().startsWith(filePrefix.toLowerCase()); } }; File[] files = directory.listFiles(myFilter); From d7a41cf1fad2349ee7486a63133aa9e259b062d1 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 10 Mar 2020 10:34:00 +0545 Subject: [PATCH 07/34] updated for latest version of flutter --- .gitignore | 2 ++ example/android/gradle.properties | 1 + example/pubspec.lock | 47 ++++++++++++++++++++++--------- pubspec.lock | 2 +- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index e9dc58d3..e4a2f874 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ .pub/ build/ +example/ios/Flutter/flutter_export_environment.sh +example/.flutter-plugins-dependencies diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 8bd86f68..7be3d8b4 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1 +1,2 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true diff --git a/example/pubspec.lock b/example/pubspec.lock index 13d20a01..90f25037 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,20 +1,34 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.4.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" charcode: dependency: transitive description: @@ -42,7 +56,7 @@ packages: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" + version: "2.1.3" cupertino_icons: dependency: "direct main" description: @@ -102,6 +116,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.3" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" infinite_listview: dependency: transitive description: @@ -115,14 +136,14 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.6" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.1.8" numberpicker: dependency: transitive description: @@ -136,7 +157,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.6.4" path_drawing: dependency: transitive description: @@ -164,21 +185,21 @@ packages: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0+1" petitparser: dependency: transitive description: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.4.0" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.5" rxdart: dependency: transitive description: @@ -225,7 +246,7 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" synchronized: dependency: transitive description: @@ -246,7 +267,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.11" typed_data: dependency: transitive description: @@ -274,7 +295,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "3.3.1" + version: "3.5.0" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.4.0 <3.0.0" flutter: ">=1.6.0 <2.0.0" diff --git a/pubspec.lock b/pubspec.lock index 3a13e9c4..a7c6d65a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -89,7 +89,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.1.8" numberpicker: dependency: "direct main" description: From 7525fe60c53b01b2a8d278cd92004065961fcc83 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 10 Mar 2020 10:36:52 +0545 Subject: [PATCH 08/34] and upgraded version of viewer using the pageview #supports swipe gestures to move to next page and previous page #loads page as required --- example/lib/main.dart | 18 ++- lib/flutter_plugin_pdf_viewer.dart | 1 + lib/src/viewer_v2.dart | 223 +++++++++++++++++++++++++++++ 3 files changed, 239 insertions(+), 3 deletions(-) create mode 100644 lib/src/viewer_v2.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index 0f5f2dce..5ed4423e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -11,6 +11,7 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { bool _isLoading = true; PDFDocument document; + bool _useV2 = true; @override void initState() { @@ -45,6 +46,14 @@ class _MyAppState extends State { child: Column( children: [ SizedBox(height: 36), + ListTile( + title: Text(_useV2 ? 'User Viewer V1' : 'Use Viewer V2'), + onTap: () { + setState(() { + _useV2 = !_useV2; + }); + }, + ), ListTile( title: Text('Load from Assets'), onTap: () { @@ -70,9 +79,12 @@ class _MyAppState extends State { title: const Text('FlutterPluginPDFViewer'), ), body: Center( - child: _isLoading - ? Center(child: CircularProgressIndicator()) - : PDFViewer(document: document)), + child: _isLoading + ? Center(child: CircularProgressIndicator()) + : _useV2 + ? PDFViewerV2(document: document) + : PDFViewer(document: document), + ), ), ); } diff --git a/lib/flutter_plugin_pdf_viewer.dart b/lib/flutter_plugin_pdf_viewer.dart index 77a8af18..4e401550 100644 --- a/lib/flutter_plugin_pdf_viewer.dart +++ b/lib/flutter_plugin_pdf_viewer.dart @@ -4,3 +4,4 @@ export 'src/document.dart' show PDFDocument; export 'src/page.dart' show PDFPage; export 'src/viewer.dart' show PDFViewer; export 'src/tooltip.dart' show PDFViewerTooltip; +export 'src/viewer_v2.dart' show PDFViewerV2; diff --git a/lib/src/viewer_v2.dart b/lib/src/viewer_v2.dart new file mode 100644 index 00000000..0ac0d1a2 --- /dev/null +++ b/lib/src/viewer_v2.dart @@ -0,0 +1,223 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_plugin_pdf_viewer/flutter_plugin_pdf_viewer.dart'; +import 'package:numberpicker/numberpicker.dart'; + +enum IndicatorPosition { topLeft, topRight, bottomLeft, bottomRight } + +class PDFViewerV2 extends StatefulWidget { + final PDFDocument document; + final Color indicatorText; + final Color indicatorBackground; + final IndicatorPosition indicatorPosition; + final bool showIndicator; + final bool showPicker; + final bool showNavigation; + final PDFViewerTooltip tooltip; + + PDFViewerV2( + {Key key, + @required this.document, + this.indicatorText = Colors.white, + this.indicatorBackground = Colors.black54, + this.showIndicator = true, + this.showPicker = true, + this.showNavigation = true, + this.tooltip = const PDFViewerTooltip(), + this.indicatorPosition = IndicatorPosition.topRight}) + : super(key: key); + + _PDFViewerV2State createState() => _PDFViewerV2State(); +} + +class _PDFViewerV2State extends State { + bool _isLoading = true; + int _pageNumber = 1; + List _pages; + PageController _pageController; + final Duration animationDuration = Duration(milliseconds: 200); + final Curve animationCurve = Curves.easeIn; + + @override + void initState() { + super.initState(); + _pages = List(widget.document.count); + _pageController = PageController(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _pageNumber = 1; + _isLoading = true; + _pages = List(widget.document.count); + // _loadAllPages(); + _loadPage(); + } + + @override + void didUpdateWidget(PDFViewerV2 oldWidget) { + super.didUpdateWidget(oldWidget); + } + + _loadPage() async { + if(_pages[_pageNumber-1] != null) return; + setState(() { + _isLoading = true; + }); + final data = await widget.document.get(page: _pageNumber); + _pages[_pageNumber-1] = data; + if(mounted) { + setState(() { + _isLoading = false; + }); + } + } + + _animateToPage() { + _pageController.animateToPage(_pageNumber-1, duration: animationDuration, curve: animationCurve); + } + _jumpToPage() { + _pageController.jumpToPage(_pageNumber-1); + } + + Widget _drawIndicator() { + Widget child = GestureDetector( + onTap: _pickPage, + child: Container( + padding: + EdgeInsets.only(top: 4.0, left: 16.0, bottom: 4.0, right: 16.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(4.0), + color: widget.indicatorBackground), + child: Text("$_pageNumber/${widget.document.count}", + style: TextStyle( + color: widget.indicatorText, + fontSize: 16.0, + fontWeight: FontWeight.w400)))); + + switch (widget.indicatorPosition) { + case IndicatorPosition.topLeft: + return Positioned(top: 20, left: 20, child: child); + case IndicatorPosition.topRight: + return Positioned(top: 20, right: 20, child: child); + case IndicatorPosition.bottomLeft: + return Positioned(bottom: 20, left: 20, child: child); + case IndicatorPosition.bottomRight: + return Positioned(bottom: 20, right: 20, child: child); + default: + return Positioned(top: 20, right: 20, child: child); + } + } + + _pickPage() { + showDialog( + context: context, + builder: (BuildContext context) { + return NumberPickerDialog.integer( + title: Text(widget.tooltip.pick), + minValue: 1, + cancelWidget: Container(), + maxValue: widget.document.count, + initialIntegerValue: _pageNumber, + ); + }).then((int value) { + if (value != null) { + _pageNumber = value; + _animateToPage(); + } + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Stack( + children: [ + PageView.builder( + onPageChanged: (page) { + setState(() { + _pageNumber = page+1; + }); + _loadPage(); + }, + controller: _pageController, + itemCount: _pages?.length ?? 0, + itemBuilder: (context,index) => _pages[index] == null ? Center(child: CircularProgressIndicator(),) : _pages[index], + ), + (widget.showIndicator && !_isLoading) + ? _drawIndicator() + : Container(), + ], + ), + floatingActionButton: widget.showPicker + ? FloatingActionButton( + elevation: 4.0, + tooltip: widget.tooltip.jump, + child: Icon(Icons.view_carousel), + onPressed: () { + _pickPage(); + }, + ) + : null, + floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, + bottomNavigationBar: (widget.showNavigation || widget.document.count > 1) + ? BottomAppBar( + child: new Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + child: IconButton( + icon: Icon(Icons.first_page), + tooltip: widget.tooltip.first, + onPressed: () { + _pageNumber = 1; + _jumpToPage(); + }, + ), + ), + Expanded( + child: IconButton( + icon: Icon(Icons.chevron_left), + tooltip: widget.tooltip.previous, + onPressed: () { + _pageNumber--; + if (1 > _pageNumber) { + _pageNumber = 1; + } + _animateToPage(); + }, + ), + ), + widget.showPicker + ? Expanded(child: Text('')) + : SizedBox(width: 1), + Expanded( + child: IconButton( + icon: Icon(Icons.chevron_right), + tooltip: widget.tooltip.next, + onPressed: () { + _pageNumber++; + if (widget.document.count < _pageNumber) { + _pageNumber = widget.document.count; + } + _animateToPage(); + }, + ), + ), + Expanded( + child: IconButton( + icon: Icon(Icons.last_page), + tooltip: widget.tooltip.last, + onPressed: () { + _pageNumber = widget.document.count; + _jumpToPage(); + }, + ), + ), + ], + ), + ) + : Container(), + ); + } +} From 5c97a36c2fd5fb91d288ddc98c76b74564a73dae Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 10 Mar 2020 10:39:08 +0545 Subject: [PATCH 09/34] disable navigation buttons based on the _pageNumber value --- lib/src/viewer_v2.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/viewer_v2.dart b/lib/src/viewer_v2.dart index 0ac0d1a2..aec02701 100644 --- a/lib/src/viewer_v2.dart +++ b/lib/src/viewer_v2.dart @@ -123,7 +123,7 @@ class _PDFViewerV2State extends State { }).then((int value) { if (value != null) { _pageNumber = value; - _animateToPage(); + _jumpToPage(); } }); } @@ -169,7 +169,7 @@ class _PDFViewerV2State extends State { child: IconButton( icon: Icon(Icons.first_page), tooltip: widget.tooltip.first, - onPressed: () { + onPressed: _pageNumber == 1 ? null : () { _pageNumber = 1; _jumpToPage(); }, @@ -179,7 +179,7 @@ class _PDFViewerV2State extends State { child: IconButton( icon: Icon(Icons.chevron_left), tooltip: widget.tooltip.previous, - onPressed: () { + onPressed: _pageNumber == 1 ? null : () { _pageNumber--; if (1 > _pageNumber) { _pageNumber = 1; @@ -195,7 +195,7 @@ class _PDFViewerV2State extends State { child: IconButton( icon: Icon(Icons.chevron_right), tooltip: widget.tooltip.next, - onPressed: () { + onPressed: _pageNumber == widget.document.count ? null : () { _pageNumber++; if (widget.document.count < _pageNumber) { _pageNumber = widget.document.count; @@ -208,7 +208,7 @@ class _PDFViewerV2State extends State { child: IconButton( icon: Icon(Icons.last_page), tooltip: widget.tooltip.last, - onPressed: () { + onPressed: _pageNumber == widget.document.count ? null : () { _pageNumber = widget.document.count; _jumpToPage(); }, From c462df9058e10e8b7806f4d02391dd5696b4b1d8 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 18 Mar 2020 14:47:36 +0545 Subject: [PATCH 10/34] changing names --- README.md | 6 +++--- .../android/app/src/main/AndroidManifest.xml | 2 +- example/lib/main.dart | 2 +- example/pubspec.lock | 18 +++++++++--------- example/pubspec.yaml | 6 +++--- ..._plugin_pdf_viewer.dart => pdf_viewer.dart} | 2 +- lib/src/document.dart | 2 +- lib/src/viewer.dart | 2 +- lib/src/viewer_v2.dart | 2 +- pubspec.lock | 4 ++-- pubspec.yaml | 10 +++++----- 11 files changed, 28 insertions(+), 28 deletions(-) rename lib/{flutter_plugin_pdf_viewer.dart => pdf_viewer.dart} (86%) diff --git a/README.md b/README.md index 9c8f116a..8b46d894 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# flutter_plugin_pdf_viewer +# pdf_viewer A flutter plugin for handling PDF files. Works on both Android & iOS ## Installation -Add *flutter_plugin_pdf_viewer* as a dependency in [your pubspec.yaml file](https://flutter.io/platform-plugins/). +Add *pdf_viewer* as a dependency in [your pubspec.yaml file](https://flutter.io/platform-plugins/). ``` -flutter_plugin_pdf_viewer: any +pdf_viewer: any ``` --- diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index c2e1974f..e0cb5b2c 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -10,7 +10,7 @@ FlutterApplication and put your custom class here. --> runApp(MyApp()); diff --git a/example/pubspec.lock b/example/pubspec.lock index 90f25037..ac471a36 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -82,14 +82,7 @@ packages: name: flutter_cache_manager url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" - flutter_plugin_pdf_viewer: - dependency: "direct dev" - description: - path: ".." - relative: true - source: path - version: "1.0.7" + version: "1.1.3" flutter_svg: dependency: transitive description: @@ -150,7 +143,7 @@ packages: name: numberpicker url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.2.0" path: dependency: transitive description: @@ -179,6 +172,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.2" + pdf_viewer: + dependency: "direct dev" + description: + path: ".." + relative: true + source: path + version: "1.0.7" pedantic: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 643f6743..2b519951 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,5 +1,5 @@ -name: flutter_plugin_pdf_viewer_example -description: Demonstrates how to use the flutter_plugin_pdf_viewer plugin. +name: pdf_viewer_example +description: Demonstrates how to use the pdf_viewer plugin. publish_to: 'none' environment: @@ -17,7 +17,7 @@ dev_dependencies: flutter_test: sdk: flutter - flutter_plugin_pdf_viewer: + pdf_viewer: path: ../ flutter: diff --git a/lib/flutter_plugin_pdf_viewer.dart b/lib/pdf_viewer.dart similarity index 86% rename from lib/flutter_plugin_pdf_viewer.dart rename to lib/pdf_viewer.dart index 4e401550..7c29f0f0 100644 --- a/lib/flutter_plugin_pdf_viewer.dart +++ b/lib/pdf_viewer.dart @@ -1,4 +1,4 @@ -library flutter_plugin_pdf_viewer; +library pdf_viewer; export 'src/document.dart' show PDFDocument; export 'src/page.dart' show PDFPage; diff --git a/lib/src/document.dart b/lib/src/document.dart index 48442978..5fe118da 100644 --- a/lib/src/document.dart +++ b/lib/src/document.dart @@ -3,7 +3,7 @@ import 'dart:io'; import 'package:flutter/services.dart'; import 'package:flutter_cache_manager/flutter_cache_manager.dart'; -import 'package:flutter_plugin_pdf_viewer/src/page.dart'; +import 'package:pdf_viewer/src/page.dart'; import 'package:path_provider/path_provider.dart'; import 'package:rxdart/rxdart.dart'; diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index 9326a223..5f433f27 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:flutter_plugin_pdf_viewer/flutter_plugin_pdf_viewer.dart'; +import 'package:pdf_viewer/pdf_viewer.dart'; import 'package:numberpicker/numberpicker.dart'; import 'tooltip.dart'; diff --git a/lib/src/viewer_v2.dart b/lib/src/viewer_v2.dart index aec02701..2064c5f9 100644 --- a/lib/src/viewer_v2.dart +++ b/lib/src/viewer_v2.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:flutter_plugin_pdf_viewer/flutter_plugin_pdf_viewer.dart'; +import 'package:pdf_viewer/pdf_viewer.dart'; import 'package:numberpicker/numberpicker.dart'; enum IndicatorPosition { topLeft, topRight, bottomLeft, bottomRight } diff --git a/pubspec.lock b/pubspec.lock index a7c6d65a..bdfaafba 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -54,7 +54,7 @@ packages: name: flutter_cache_manager url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.3" flutter_svg: dependency: transitive description: @@ -96,7 +96,7 @@ packages: name: numberpicker url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.2.0" path: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 3b97efdd..8f1af9d3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,8 +1,8 @@ -name: flutter_plugin_pdf_viewer +name: pdf_viewer description: A flutter plugin for handling PDF files. Works on both Android & iOS version: 1.0.7 -author: Tiago Ribeiro -homepage: https://github.com/CrossPT/flutter_plugin_pdf_viewer +author: Damodar Lohani +homepage: https://github.com/lohanidamodar/pdf_viewer environment: sdk: ">=2.1.0 <3.0.0" @@ -10,10 +10,10 @@ environment: dependencies: flutter: sdk: flutter - flutter_cache_manager: ^1.0.0 + flutter_cache_manager: ^1.1.3 path_provider: ^1.1.0 rxdart: ^0.21.0 - numberpicker: ^1.0.0 + numberpicker: ^1.2.0 flutter_advanced_networkimage: ^0.5.0 flutter: From 2d42e6f41d9a11600882bb5f5c841cda044eb421 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 18 Mar 2020 14:48:57 +0545 Subject: [PATCH 11/34] link to original project --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b46d894..98226314 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # pdf_viewer -A flutter plugin for handling PDF files. Works on both Android & iOS +A flutter plugin for handling PDF files. Works on both Android & iOS. Originally forked from (https://github.com/CrossPT/flutter_plugin_pdf_viewer). ## Installation From 930d8b69f059976d38ebe93b8d3dc1580e716771 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 18 Mar 2020 14:51:06 +0545 Subject: [PATCH 12/34] updating viewer v2 as main viewer --- example/lib/main.dart | 13 +-- lib/pdf_viewer.dart | 1 - lib/src/viewer.dart | 80 +++++++++------ lib/src/viewer_v2.dart | 223 ----------------------------------------- 4 files changed, 51 insertions(+), 266 deletions(-) delete mode 100644 lib/src/viewer_v2.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index e6165862..6f10042f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -11,7 +11,6 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { bool _isLoading = true; PDFDocument document; - bool _useV2 = true; @override void initState() { @@ -46,14 +45,6 @@ class _MyAppState extends State { child: Column( children: [ SizedBox(height: 36), - ListTile( - title: Text(_useV2 ? 'User Viewer V1' : 'Use Viewer V2'), - onTap: () { - setState(() { - _useV2 = !_useV2; - }); - }, - ), ListTile( title: Text('Load from Assets'), onTap: () { @@ -81,9 +72,7 @@ class _MyAppState extends State { body: Center( child: _isLoading ? Center(child: CircularProgressIndicator()) - : _useV2 - ? PDFViewerV2(document: document) - : PDFViewer(document: document), + : PDFViewer(document: document) ), ), ); diff --git a/lib/pdf_viewer.dart b/lib/pdf_viewer.dart index 7c29f0f0..ed7b7e56 100644 --- a/lib/pdf_viewer.dart +++ b/lib/pdf_viewer.dart @@ -4,4 +4,3 @@ export 'src/document.dart' show PDFDocument; export 'src/page.dart' show PDFPage; export 'src/viewer.dart' show PDFViewer; export 'src/tooltip.dart' show PDFViewerTooltip; -export 'src/viewer_v2.dart' show PDFViewerV2; diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index 5f433f27..daa98de0 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:pdf_viewer/pdf_viewer.dart'; import 'package:numberpicker/numberpicker.dart'; -import 'tooltip.dart'; enum IndicatorPosition { topLeft, topRight, bottomLeft, bottomRight } @@ -33,43 +32,54 @@ class PDFViewer extends StatefulWidget { class _PDFViewerState extends State { bool _isLoading = true; int _pageNumber = 1; - int _oldPage = 0; - PDFPage _page; - List _pages = List(); + List _pages; + PageController _pageController; + final Duration animationDuration = Duration(milliseconds: 200); + final Curve animationCurve = Curves.easeIn; + + @override + void initState() { + super.initState(); + _pages = List(widget.document.count); + _pageController = PageController(); + } @override void didChangeDependencies() { super.didChangeDependencies(); - _oldPage = 0; _pageNumber = 1; _isLoading = true; - _pages.clear(); + _pages = List(widget.document.count); + // _loadAllPages(); _loadPage(); } @override void didUpdateWidget(PDFViewer oldWidget) { super.didUpdateWidget(oldWidget); - _oldPage = 0; - _pageNumber = 1; - _isLoading = true; - _pages.clear(); - _loadPage(); } _loadPage() async { - setState(() => _isLoading = true); - if (_oldPage == 0) { - _page = await widget.document.get(page: _pageNumber); - } else if (_oldPage != _pageNumber) { - _oldPage = _pageNumber; - _page = await widget.document.get(page: _pageNumber); - } - if(this.mounted) { - setState(() => _isLoading = false); + if(_pages[_pageNumber-1] != null) return; + setState(() { + _isLoading = true; + }); + final data = await widget.document.get(page: _pageNumber); + _pages[_pageNumber-1] = data; + if(mounted) { + setState(() { + _isLoading = false; + }); } } + _animateToPage() { + _pageController.animateToPage(_pageNumber-1, duration: animationDuration, curve: animationCurve); + } + _jumpToPage() { + _pageController.jumpToPage(_pageNumber-1); + } + Widget _drawIndicator() { Widget child = GestureDetector( onTap: _pickPage, @@ -113,7 +123,7 @@ class _PDFViewerState extends State { }).then((int value) { if (value != null) { _pageNumber = value; - _loadPage(); + _jumpToPage(); } }); } @@ -123,7 +133,17 @@ class _PDFViewerState extends State { return Scaffold( body: Stack( children: [ - _isLoading ? Center(child: CircularProgressIndicator()) : _page, + PageView.builder( + onPageChanged: (page) { + setState(() { + _pageNumber = page+1; + }); + _loadPage(); + }, + controller: _pageController, + itemCount: _pages?.length ?? 0, + itemBuilder: (context,index) => _pages[index] == null ? Center(child: CircularProgressIndicator(),) : _pages[index], + ), (widget.showIndicator && !_isLoading) ? _drawIndicator() : Container(), @@ -149,9 +169,9 @@ class _PDFViewerState extends State { child: IconButton( icon: Icon(Icons.first_page), tooltip: widget.tooltip.first, - onPressed: () { + onPressed: _pageNumber == 1 ? null : () { _pageNumber = 1; - _loadPage(); + _jumpToPage(); }, ), ), @@ -159,12 +179,12 @@ class _PDFViewerState extends State { child: IconButton( icon: Icon(Icons.chevron_left), tooltip: widget.tooltip.previous, - onPressed: () { + onPressed: _pageNumber == 1 ? null : () { _pageNumber--; if (1 > _pageNumber) { _pageNumber = 1; } - _loadPage(); + _animateToPage(); }, ), ), @@ -175,12 +195,12 @@ class _PDFViewerState extends State { child: IconButton( icon: Icon(Icons.chevron_right), tooltip: widget.tooltip.next, - onPressed: () { + onPressed: _pageNumber == widget.document.count ? null : () { _pageNumber++; if (widget.document.count < _pageNumber) { _pageNumber = widget.document.count; } - _loadPage(); + _animateToPage(); }, ), ), @@ -188,9 +208,9 @@ class _PDFViewerState extends State { child: IconButton( icon: Icon(Icons.last_page), tooltip: widget.tooltip.last, - onPressed: () { + onPressed: _pageNumber == widget.document.count ? null : () { _pageNumber = widget.document.count; - _loadPage(); + _jumpToPage(); }, ), ), diff --git a/lib/src/viewer_v2.dart b/lib/src/viewer_v2.dart deleted file mode 100644 index 2064c5f9..00000000 --- a/lib/src/viewer_v2.dart +++ /dev/null @@ -1,223 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:pdf_viewer/pdf_viewer.dart'; -import 'package:numberpicker/numberpicker.dart'; - -enum IndicatorPosition { topLeft, topRight, bottomLeft, bottomRight } - -class PDFViewerV2 extends StatefulWidget { - final PDFDocument document; - final Color indicatorText; - final Color indicatorBackground; - final IndicatorPosition indicatorPosition; - final bool showIndicator; - final bool showPicker; - final bool showNavigation; - final PDFViewerTooltip tooltip; - - PDFViewerV2( - {Key key, - @required this.document, - this.indicatorText = Colors.white, - this.indicatorBackground = Colors.black54, - this.showIndicator = true, - this.showPicker = true, - this.showNavigation = true, - this.tooltip = const PDFViewerTooltip(), - this.indicatorPosition = IndicatorPosition.topRight}) - : super(key: key); - - _PDFViewerV2State createState() => _PDFViewerV2State(); -} - -class _PDFViewerV2State extends State { - bool _isLoading = true; - int _pageNumber = 1; - List _pages; - PageController _pageController; - final Duration animationDuration = Duration(milliseconds: 200); - final Curve animationCurve = Curves.easeIn; - - @override - void initState() { - super.initState(); - _pages = List(widget.document.count); - _pageController = PageController(); - } - - @override - void didChangeDependencies() { - super.didChangeDependencies(); - _pageNumber = 1; - _isLoading = true; - _pages = List(widget.document.count); - // _loadAllPages(); - _loadPage(); - } - - @override - void didUpdateWidget(PDFViewerV2 oldWidget) { - super.didUpdateWidget(oldWidget); - } - - _loadPage() async { - if(_pages[_pageNumber-1] != null) return; - setState(() { - _isLoading = true; - }); - final data = await widget.document.get(page: _pageNumber); - _pages[_pageNumber-1] = data; - if(mounted) { - setState(() { - _isLoading = false; - }); - } - } - - _animateToPage() { - _pageController.animateToPage(_pageNumber-1, duration: animationDuration, curve: animationCurve); - } - _jumpToPage() { - _pageController.jumpToPage(_pageNumber-1); - } - - Widget _drawIndicator() { - Widget child = GestureDetector( - onTap: _pickPage, - child: Container( - padding: - EdgeInsets.only(top: 4.0, left: 16.0, bottom: 4.0, right: 16.0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(4.0), - color: widget.indicatorBackground), - child: Text("$_pageNumber/${widget.document.count}", - style: TextStyle( - color: widget.indicatorText, - fontSize: 16.0, - fontWeight: FontWeight.w400)))); - - switch (widget.indicatorPosition) { - case IndicatorPosition.topLeft: - return Positioned(top: 20, left: 20, child: child); - case IndicatorPosition.topRight: - return Positioned(top: 20, right: 20, child: child); - case IndicatorPosition.bottomLeft: - return Positioned(bottom: 20, left: 20, child: child); - case IndicatorPosition.bottomRight: - return Positioned(bottom: 20, right: 20, child: child); - default: - return Positioned(top: 20, right: 20, child: child); - } - } - - _pickPage() { - showDialog( - context: context, - builder: (BuildContext context) { - return NumberPickerDialog.integer( - title: Text(widget.tooltip.pick), - minValue: 1, - cancelWidget: Container(), - maxValue: widget.document.count, - initialIntegerValue: _pageNumber, - ); - }).then((int value) { - if (value != null) { - _pageNumber = value; - _jumpToPage(); - } - }); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - body: Stack( - children: [ - PageView.builder( - onPageChanged: (page) { - setState(() { - _pageNumber = page+1; - }); - _loadPage(); - }, - controller: _pageController, - itemCount: _pages?.length ?? 0, - itemBuilder: (context,index) => _pages[index] == null ? Center(child: CircularProgressIndicator(),) : _pages[index], - ), - (widget.showIndicator && !_isLoading) - ? _drawIndicator() - : Container(), - ], - ), - floatingActionButton: widget.showPicker - ? FloatingActionButton( - elevation: 4.0, - tooltip: widget.tooltip.jump, - child: Icon(Icons.view_carousel), - onPressed: () { - _pickPage(); - }, - ) - : null, - floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, - bottomNavigationBar: (widget.showNavigation || widget.document.count > 1) - ? BottomAppBar( - child: new Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Expanded( - child: IconButton( - icon: Icon(Icons.first_page), - tooltip: widget.tooltip.first, - onPressed: _pageNumber == 1 ? null : () { - _pageNumber = 1; - _jumpToPage(); - }, - ), - ), - Expanded( - child: IconButton( - icon: Icon(Icons.chevron_left), - tooltip: widget.tooltip.previous, - onPressed: _pageNumber == 1 ? null : () { - _pageNumber--; - if (1 > _pageNumber) { - _pageNumber = 1; - } - _animateToPage(); - }, - ), - ), - widget.showPicker - ? Expanded(child: Text('')) - : SizedBox(width: 1), - Expanded( - child: IconButton( - icon: Icon(Icons.chevron_right), - tooltip: widget.tooltip.next, - onPressed: _pageNumber == widget.document.count ? null : () { - _pageNumber++; - if (widget.document.count < _pageNumber) { - _pageNumber = widget.document.count; - } - _animateToPage(); - }, - ), - ), - Expanded( - child: IconButton( - icon: Icon(Icons.last_page), - tooltip: widget.tooltip.last, - onPressed: _pageNumber == widget.document.count ? null : () { - _pageNumber = widget.document.count; - _jumpToPage(); - }, - ), - ), - ], - ), - ) - : Container(), - ); - } -} From 62074e16a1ed9a9e1c02e1c873c93a53f5c2c41c Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 18 Mar 2020 14:54:18 +0545 Subject: [PATCH 13/34] export show IndicatorPosition enum --- lib/pdf_viewer.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pdf_viewer.dart b/lib/pdf_viewer.dart index ed7b7e56..dc47102f 100644 --- a/lib/pdf_viewer.dart +++ b/lib/pdf_viewer.dart @@ -2,5 +2,5 @@ library pdf_viewer; export 'src/document.dart' show PDFDocument; export 'src/page.dart' show PDFPage; -export 'src/viewer.dart' show PDFViewer; +export 'src/viewer.dart' show PDFViewer, IndicatorPosition; export 'src/tooltip.dart' show PDFViewerTooltip; From 2285fa01e523c081acfe984d166685a86271686d Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 18 Mar 2020 15:24:18 +0545 Subject: [PATCH 14/34] navigation builder --- example/lib/main.dart | 37 ++++++++++++++++++++++++++++++++++++- lib/src/viewer.dart | 18 +++++++++++++----- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 6f10042f..0659d8cd 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -72,7 +72,42 @@ class _MyAppState extends State { body: Center( child: _isLoading ? Center(child: CircularProgressIndicator()) - : PDFViewer(document: document) + : PDFViewer( + document: document, + //uncomment below code to replace bottom navigation with your own + /* navigationBuilder: + (context, page, totalPages, jumpToPage, animateToPage) { + return ButtonBar( + alignment: MainAxisAlignment.spaceEvenly, + children: [ + IconButton( + icon: Icon(Icons.first_page), + onPressed: () { + jumpToPage()(page: 0); + }, + ), + IconButton( + icon: Icon(Icons.arrow_back), + onPressed: () { + animateToPage(page: page - 2); + }, + ), + IconButton( + icon: Icon(Icons.arrow_forward), + onPressed: () { + animateToPage(page: page); + }, + ), + IconButton( + icon: Icon(Icons.last_page), + onPressed: () { + jumpToPage(page: totalPages - 1); + }, + ), + ], + ); + }, */ + ), ), ), ); diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index daa98de0..5a32be10 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -13,6 +13,7 @@ class PDFViewer extends StatefulWidget { final bool showPicker; final bool showNavigation; final PDFViewerTooltip tooltip; + final Widget Function(BuildContext, int pageNumber, int totalPages, void Function({int page}) jumpToPage, void Function({int page}) animateToPage,) navigationBuilder; PDFViewer( {Key key, @@ -23,6 +24,7 @@ class PDFViewer extends StatefulWidget { this.showPicker = true, this.showNavigation = true, this.tooltip = const PDFViewerTooltip(), + this.navigationBuilder, this.indicatorPosition = IndicatorPosition.topRight}) : super(key: key); @@ -73,11 +75,11 @@ class _PDFViewerState extends State { } } - _animateToPage() { - _pageController.animateToPage(_pageNumber-1, duration: animationDuration, curve: animationCurve); + _animateToPage({int page}) { + _pageController.animateToPage(page != null ? page : _pageNumber-1, duration: animationDuration, curve: animationCurve); } - _jumpToPage() { - _pageController.jumpToPage(_pageNumber-1); + _jumpToPage({int page}) { + _pageController.jumpToPage(page != null ? page : _pageNumber-1); } Widget _drawIndicator() { @@ -161,7 +163,13 @@ class _PDFViewerState extends State { : null, floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, bottomNavigationBar: (widget.showNavigation || widget.document.count > 1) - ? BottomAppBar( + ? widget.navigationBuilder != null ? widget.navigationBuilder( + context, + _pageNumber, + widget.document.count, + _jumpToPage, + _animateToPage, + ) : BottomAppBar( child: new Row( mainAxisAlignment: MainAxisAlignment.center, children: [ From d28d2bad265904ade491a8a9a93a88c0b15783f9 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 18 Mar 2020 15:28:13 +0545 Subject: [PATCH 15/34] hide picker on indicator tap if showPicker is false --- lib/src/viewer.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index 5a32be10..060a5d72 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -84,7 +84,7 @@ class _PDFViewerState extends State { Widget _drawIndicator() { Widget child = GestureDetector( - onTap: _pickPage, + onTap: widget.showPicker ? _pickPage : null, child: Container( padding: EdgeInsets.only(top: 4.0, left: 16.0, bottom: 4.0, right: 16.0), From aafb2bcab3490454434a006e2b98ff8512d9cfad Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 18 Mar 2020 15:29:05 +0545 Subject: [PATCH 16/34] version 1.0.0 --- CHANGELOG.md | 44 ++------------------------------------------ example/pubspec.lock | 2 +- pubspec.yaml | 3 +-- 3 files changed, 4 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3b834e0..a9095bdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,43 +1,3 @@ -## 1.0.7 - -- Updated project to meet changed requirements by Flutter -- Updated third-party dependencies -- Fixes issue #21, #23 - -## 1.0.6 - -- Fixed issue in 1.0.5 on iOS that caused xcode build to fail - -## 1.0.5 - -- Fixed bug in iOS where due to caching of Flutter ImageProvider when switching documents old pages would persist -- Added more cases in example demo - -## 1.0.4 - -- Refactored PDFdocument.getAllPages() method (Thanks for @SergioBernal8 for PR ) -- Added white background to page (iOS) -- Changed page resolution in iOS to 300 dpi -- Moved tooltips to a proper class - -## 1.0.3 - -- Added white background to page (Android) -- Fixed cocoapods name -- User can now define tooltips and page selection dialog strings -- Tapping on page indicator now prompts to user to page selection dialog -- Added zoom to PDFPage - -## 1.0.2 - -- Bottom appbar no longer appears if PDF has only one page (Thanks for @markathomas for suggesting this ) -- Fixed opening PDF from assets not working. -- Example now opens file from assets - -## 1.0.1 - -- Updated readme.md and added screenshots to package - ## 1.0.0 - -- Initial release \ No newline at end of file +- First upgraded version after fork +- Cool new customization features \ No newline at end of file diff --git a/example/pubspec.lock b/example/pubspec.lock index ac471a36..6a8c3656 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -178,7 +178,7 @@ packages: path: ".." relative: true source: path - version: "1.0.7" + version: "1.0.0" pedantic: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 8f1af9d3..23365641 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,6 @@ name: pdf_viewer description: A flutter plugin for handling PDF files. Works on both Android & iOS -version: 1.0.7 -author: Damodar Lohani +version: 1.0.0 homepage: https://github.com/lohanidamodar/pdf_viewer environment: From fcd715be66c23a485bf5bd48ce801f460e880f1e Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 18 Mar 2020 15:34:50 +0545 Subject: [PATCH 17/34] name changing --- README.md | 6 +++--- example/lib/main.dart | 2 +- example/pubspec.lock | 14 +++++++------- example/pubspec.yaml | 6 +++--- lib/{pdf_viewer.dart => advance_pdf_viewer.dart} | 2 +- lib/src/document.dart | 2 +- lib/src/viewer.dart | 2 +- pubspec.yaml | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) rename lib/{pdf_viewer.dart => advance_pdf_viewer.dart} (87%) diff --git a/README.md b/README.md index 98226314..3f93643d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# pdf_viewer +# advance_pdf_viewer A flutter plugin for handling PDF files. Works on both Android & iOS. Originally forked from (https://github.com/CrossPT/flutter_plugin_pdf_viewer). ## Installation -Add *pdf_viewer* as a dependency in [your pubspec.yaml file](https://flutter.io/platform-plugins/). +Add *advance_pdf_viewer* as a dependency in [your pubspec.yaml file](https://flutter.io/platform-plugins/). ``` -pdf_viewer: any +advance_pdf_viewer: any ``` --- diff --git a/example/lib/main.dart b/example/lib/main.dart index 0659d8cd..e921bd4e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:pdf_viewer/pdf_viewer.dart'; +import 'package:advance_pdf_viewer/advance_pdf_viewer.dart'; void main() => runApp(MyApp()); diff --git a/example/pubspec.lock b/example/pubspec.lock index 6a8c3656..211c1aa9 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,6 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + advance_pdf_viewer: + dependency: "direct dev" + description: + path: ".." + relative: true + source: path + version: "1.0.0" archive: dependency: transitive description: @@ -172,13 +179,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.2" - pdf_viewer: - dependency: "direct dev" - description: - path: ".." - relative: true - source: path - version: "1.0.0" pedantic: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 2b519951..96dfe4f2 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,5 +1,5 @@ -name: pdf_viewer_example -description: Demonstrates how to use the pdf_viewer plugin. +name: advance_pdf_viewer_example +description: Demonstrates how to use the advance_pdf_viewer plugin. publish_to: 'none' environment: @@ -17,7 +17,7 @@ dev_dependencies: flutter_test: sdk: flutter - pdf_viewer: + advance_pdf_viewer: path: ../ flutter: diff --git a/lib/pdf_viewer.dart b/lib/advance_pdf_viewer.dart similarity index 87% rename from lib/pdf_viewer.dart rename to lib/advance_pdf_viewer.dart index dc47102f..8461921b 100644 --- a/lib/pdf_viewer.dart +++ b/lib/advance_pdf_viewer.dart @@ -1,4 +1,4 @@ -library pdf_viewer; +library advance_pdf_viewer; export 'src/document.dart' show PDFDocument; export 'src/page.dart' show PDFPage; diff --git a/lib/src/document.dart b/lib/src/document.dart index 5fe118da..9a9761ea 100644 --- a/lib/src/document.dart +++ b/lib/src/document.dart @@ -3,7 +3,7 @@ import 'dart:io'; import 'package:flutter/services.dart'; import 'package:flutter_cache_manager/flutter_cache_manager.dart'; -import 'package:pdf_viewer/src/page.dart'; +import 'package:advance_pdf_viewer/src/page.dart'; import 'package:path_provider/path_provider.dart'; import 'package:rxdart/rxdart.dart'; diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index 060a5d72..81af3286 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:pdf_viewer/pdf_viewer.dart'; +import 'package:advance_pdf_viewer/advance_pdf_viewer.dart'; import 'package:numberpicker/numberpicker.dart'; enum IndicatorPosition { topLeft, topRight, bottomLeft, bottomRight } diff --git a/pubspec.yaml b/pubspec.yaml index 23365641..19ced545 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,4 +1,4 @@ -name: pdf_viewer +name: advance_pdf_viewer description: A flutter plugin for handling PDF files. Works on both Android & iOS version: 1.0.0 homepage: https://github.com/lohanidamodar/pdf_viewer From 053758c52dd714591f27707a3ea7b7cf74607eeb Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 08:07:59 +0545 Subject: [PATCH 18/34] disable slide on zooming --- lib/src/document.dart | 8 ++++---- lib/src/page.dart | 8 +++++--- lib/src/viewer.dart | 16 +++++++++++++++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/src/document.dart b/lib/src/document.dart index 9a9761ea..91c450ce 100644 --- a/lib/src/document.dart +++ b/lib/src/document.dart @@ -78,20 +78,20 @@ class PDFDocument { /// Load specific page /// /// [page] defaults to `1` and must be equal or above it - Future get({int page = 1}) async { + Future get({int page = 1, final Function(double) onZoomChanged}) async { assert(page > 0); var data = await _channel .invokeMethod('getPage', {'filePath': _filePath, 'pageNumber': page}); - return new PDFPage(data, page); + return new PDFPage(data, page,onZoomChanged: onZoomChanged,); } // Stream all pages - Observable getAll() { + Observable getAll({final Function(double) onZoomChanged}) { return Future.forEach(List(count), (i) async { print(i); final data = await _channel .invokeMethod('getPage', {'filePath': _filePath, 'pageNumber': i}); - return new PDFPage(data, 1); + return new PDFPage(data, 1,onZoomChanged: onZoomChanged,); }).asStream(); } } diff --git a/lib/src/page.dart b/lib/src/page.dart index e85e48d7..b8cfb22b 100644 --- a/lib/src/page.dart +++ b/lib/src/page.dart @@ -7,7 +7,8 @@ import 'package:flutter_advanced_networkimage/zoomable.dart'; class PDFPage extends StatefulWidget { final String imgPath; final int num; - PDFPage(this.imgPath, this.num); + final Function(double) onZoomChanged; + PDFPage(this.imgPath, this.num, {this.onZoomChanged}); @override _PDFPageState createState() => _PDFPageState(); @@ -43,10 +44,11 @@ class _PDFPageState extends State { return Container( decoration: null, child: ZoomableWidget( + onZoomChanged: widget.onZoomChanged, zoomSteps: 3, minScale: 1.0, - panLimit: 0.8, - maxScale: 3.0, + panLimit: 1.0, + maxScale: 5.0, child: Image(image: provider), )); } diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index 81af3286..35b64e5e 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -34,6 +34,7 @@ class PDFViewer extends StatefulWidget { class _PDFViewerState extends State { bool _isLoading = true; int _pageNumber = 1; + bool _swipeEnabled = true; List _pages; PageController _pageController; final Duration animationDuration = Duration(milliseconds: 200); @@ -61,12 +62,24 @@ class _PDFViewerState extends State { super.didUpdateWidget(oldWidget); } + onZoomChanged(double scale) { + if(scale != 1.0) { + setState(() { + _swipeEnabled = false; + }); + }else{ + setState(() { + _swipeEnabled = true; + }); + } + } + _loadPage() async { if(_pages[_pageNumber-1] != null) return; setState(() { _isLoading = true; }); - final data = await widget.document.get(page: _pageNumber); + final data = await widget.document.get(page: _pageNumber,onZoomChanged: onZoomChanged); _pages[_pageNumber-1] = data; if(mounted) { setState(() { @@ -136,6 +149,7 @@ class _PDFViewerState extends State { body: Stack( children: [ PageView.builder( + physics: _swipeEnabled ? null : NeverScrollableScrollPhysics(), onPageChanged: (page) { setState(() { _pageNumber = page+1; From bd414d933a3f170cd6cb00aa303fe826855c9eeb Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 08:11:02 +0545 Subject: [PATCH 19/34] version 1.0.1 --- CHANGELOG.md | 4 ++++ README.md | 4 ++-- example/pubspec.lock | 2 +- pubspec.yaml | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9095bdf..bd876b2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.1 +- Swipe control +- Zoom scale up to 5.0 + ## 1.0.0 - First upgraded version after fork - Cool new customization features \ No newline at end of file diff --git a/README.md b/README.md index 3f93643d..4ce19bf9 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Use the pre-built PDF Viewer This code produces the following view: -Demo Screenshot 1 +Demo Screenshot 1 --- @@ -66,7 +66,7 @@ This code produces the following view: * Allow password-protected files * ~~Refactor PDFDocument.getAll() method~~ * ~~Increase page resolution~~ -* Add swipe to change page +* ~~Add swipe to change page~~ --- diff --git a/example/pubspec.lock b/example/pubspec.lock index 211c1aa9..fceb5dbd 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "1.0.0" + version: "1.0.1" archive: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 19ced545..bb5c0a05 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: advance_pdf_viewer description: A flutter plugin for handling PDF files. Works on both Android & iOS -version: 1.0.0 +version: 1.0.1 homepage: https://github.com/lohanidamodar/pdf_viewer environment: From 9fe7b537be5f312ca4efef104071f40bf684dd52 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 13:17:35 +0545 Subject: [PATCH 20/34] upgraded plugins to latest version --- example/pubspec.lock | 40 ++++++++++++++++++++++++++++++++++------ lib/src/document.dart | 2 +- pubspec.lock | 42 +++++++++++++++++++++++++++++++++++------- pubspec.yaml | 6 +++--- 4 files changed, 73 insertions(+), 17 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index fceb5dbd..2636f9b2 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -82,7 +82,7 @@ packages: name: flutter_advanced_networkimage url: "https://pub.dartlang.org" source: hosted - version: "0.5.0" + version: "0.7.0" flutter_cache_manager: dependency: transitive description: @@ -96,7 +96,7 @@ packages: name: flutter_svg url: "https://pub.dartlang.org" source: hosted - version: "0.13.1" + version: "0.17.3+1" flutter_test: dependency: "direct dev" description: flutter @@ -178,7 +178,21 @@ packages: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.6.5" + path_provider_macos: + dependency: transitive + description: + name: path_provider_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.4" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" pedantic: dependency: transitive description: @@ -193,6 +207,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.4.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" quiver: dependency: transitive description: @@ -206,7 +234,7 @@ packages: name: rxdart url: "https://pub.dartlang.org" source: hosted - version: "0.21.0" + version: "0.23.1" sky_engine: dependency: transitive description: flutter @@ -297,5 +325,5 @@ packages: source: hosted version: "3.5.0" sdks: - dart: ">=2.4.0 <3.0.0" - flutter: ">=1.6.0 <2.0.0" + dart: ">=2.6.0 <3.0.0" + flutter: ">=1.10.0 <2.0.0" diff --git a/lib/src/document.dart b/lib/src/document.dart index 91c450ce..b875abd5 100644 --- a/lib/src/document.dart +++ b/lib/src/document.dart @@ -86,7 +86,7 @@ class PDFDocument { } // Stream all pages - Observable getAll({final Function(double) onZoomChanged}) { + Stream getAll({final Function(double) onZoomChanged}) { return Future.forEach(List(count), (i) async { print(i); final data = await _channel diff --git a/pubspec.lock b/pubspec.lock index bdfaafba..66b0285b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -47,7 +47,7 @@ packages: name: flutter_advanced_networkimage url: "https://pub.dartlang.org" source: hosted - version: "0.5.0" + version: "0.7.0" flutter_cache_manager: dependency: "direct main" description: @@ -61,7 +61,7 @@ packages: name: flutter_svg url: "https://pub.dartlang.org" source: hosted - version: "0.13.1" + version: "0.17.3+1" http: dependency: transitive description: @@ -103,7 +103,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.6.4" path_drawing: dependency: transitive description: @@ -124,7 +124,21 @@ packages: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.6.5" + path_provider_macos: + dependency: transitive + description: + name: path_provider_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.4" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" pedantic: dependency: transitive description: @@ -139,13 +153,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.4.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" rxdart: dependency: "direct main" description: name: rxdart url: "https://pub.dartlang.org" source: hosted - version: "0.21.0" + version: "0.23.1" sky_engine: dependency: transitive description: flutter @@ -215,5 +243,5 @@ packages: source: hosted version: "3.5.0" sdks: - dart: ">=2.4.0 <3.0.0" - flutter: ">=1.6.0 <2.0.0" + dart: ">=2.6.0 <3.0.0" + flutter: ">=1.10.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index bb5c0a05..b8af0d46 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,10 +10,10 @@ dependencies: flutter: sdk: flutter flutter_cache_manager: ^1.1.3 - path_provider: ^1.1.0 - rxdart: ^0.21.0 + path_provider: ^1.6.5 + rxdart: ^0.23.1 numberpicker: ^1.2.0 - flutter_advanced_networkimage: ^0.5.0 + flutter_advanced_networkimage: ^0.7.0 flutter: plugin: From b613c7a6eb546e25b02821f6c952890bdef5cb15 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 13:18:56 +0545 Subject: [PATCH 21/34] hide picker for one page document --- lib/src/viewer.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index 35b64e5e..d933fcdd 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -97,7 +97,7 @@ class _PDFViewerState extends State { Widget _drawIndicator() { Widget child = GestureDetector( - onTap: widget.showPicker ? _pickPage : null, + onTap: widget.showPicker && widget.document.count > 1 ? _pickPage : null, child: Container( padding: EdgeInsets.only(top: 4.0, left: 16.0, bottom: 4.0, right: 16.0), @@ -165,7 +165,7 @@ class _PDFViewerState extends State { : Container(), ], ), - floatingActionButton: widget.showPicker + floatingActionButton: widget.showPicker && widget.document.count > 1 ? FloatingActionButton( elevation: 4.0, tooltip: widget.tooltip.jump, From 5d0895677246b10624f3214f12ad9485a8e53420 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 13:19:59 +0545 Subject: [PATCH 22/34] remove rxdart dependency --- example/pubspec.lock | 9 +-------- lib/src/document.dart | 1 - pubspec.lock | 9 +-------- pubspec.yaml | 1 - 4 files changed, 2 insertions(+), 18 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 2636f9b2..ab13b656 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -228,13 +228,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.5" - rxdart: - dependency: transitive - description: - name: rxdart - url: "https://pub.dartlang.org" - source: hosted - version: "0.23.1" sky_engine: dependency: transitive description: flutter @@ -325,5 +318,5 @@ packages: source: hosted version: "3.5.0" sdks: - dart: ">=2.6.0 <3.0.0" + dart: ">=2.4.0 <3.0.0" flutter: ">=1.10.0 <2.0.0" diff --git a/lib/src/document.dart b/lib/src/document.dart index b875abd5..01095719 100644 --- a/lib/src/document.dart +++ b/lib/src/document.dart @@ -5,7 +5,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_cache_manager/flutter_cache_manager.dart'; import 'package:advance_pdf_viewer/src/page.dart'; import 'package:path_provider/path_provider.dart'; -import 'package:rxdart/rxdart.dart'; class PDFDocument { static const MethodChannel _channel = diff --git a/pubspec.lock b/pubspec.lock index 66b0285b..c771fa22 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -167,13 +167,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.2" - rxdart: - dependency: "direct main" - description: - name: rxdart - url: "https://pub.dartlang.org" - source: hosted - version: "0.23.1" sky_engine: dependency: transitive description: flutter @@ -243,5 +236,5 @@ packages: source: hosted version: "3.5.0" sdks: - dart: ">=2.6.0 <3.0.0" + dart: ">=2.4.0 <3.0.0" flutter: ">=1.10.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index b8af0d46..6dd998a7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,6 @@ dependencies: sdk: flutter flutter_cache_manager: ^1.1.3 path_provider: ^1.6.5 - rxdart: ^0.23.1 numberpicker: ^1.2.0 flutter_advanced_networkimage: ^0.7.0 From 14df4c9e2aa5262c7944b6b27d8949fa62143d8d Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 13:28:54 +0545 Subject: [PATCH 23/34] upgraded to androidX --- .gitignore | 1 + android/build.gradle | 2 +- android/gradle.properties | 2 ++ example/android/app/build.gradle | 6 +++--- example/android/gradle.properties | 2 ++ 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index e4a2f874..f226b14a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ build/ example/ios/Flutter/flutter_export_environment.sh example/.flutter-plugins-dependencies +android/.idea/ diff --git a/android/build.gradle b/android/build.gradle index fe588d94..3efafc3c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -26,7 +26,7 @@ android { defaultConfig { minSdkVersion 16 - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { disable 'InvalidPackage' diff --git a/android/gradle.properties b/android/gradle.properties index 8bd86f68..53ae0ae4 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1 +1,3 @@ +android.enableJetifier=true +android.useAndroidX=true org.gradle.jvmargs=-Xmx1536M diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index ab298322..de2e6290 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -38,7 +38,7 @@ android { targetSdkVersion 28 versionCode flutterVersionCode.toInteger() versionName flutterVersionName - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { @@ -56,6 +56,6 @@ flutter { dependencies { testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 7be3d8b4..38c8d454 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,2 +1,4 @@ org.gradle.jvmargs=-Xmx1536M android.enableR8=true +android.useAndroidX=true +android.enableJetifier=true From 19df07165114692c00959e199e07532b4bc8991f Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 13:30:13 +0545 Subject: [PATCH 24/34] allow passing optional headers for url documents --- lib/src/document.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/document.dart b/lib/src/document.dart index 01095719..d4c861e5 100644 --- a/lib/src/document.dart +++ b/lib/src/document.dart @@ -32,9 +32,9 @@ class PDFDocument { /// Load a PDF File from a given URL. /// File is saved in cache /// - static Future fromURL(String url) async { + static Future fromURL(String url,{Map headers}) async { // Download into cache - File f = await DefaultCacheManager().getSingleFile(url); + File f = await DefaultCacheManager().getSingleFile(url,headers: headers); PDFDocument document = PDFDocument(); document._filePath = f.path; try { From b018c8f3fee682f6bccd828f50a4fab8284a6700 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 13:32:33 +0545 Subject: [PATCH 25/34] formatting --- lib/src/document.dart | 20 +++-- lib/src/viewer.dart | 172 ++++++++++++++++++++++++------------------ 2 files changed, 113 insertions(+), 79 deletions(-) diff --git a/lib/src/document.dart b/lib/src/document.dart index d4c861e5..f973a532 100644 --- a/lib/src/document.dart +++ b/lib/src/document.dart @@ -32,9 +32,10 @@ class PDFDocument { /// Load a PDF File from a given URL. /// File is saved in cache /// - static Future fromURL(String url,{Map headers}) async { + static Future fromURL(String url, + {Map headers}) async { // Download into cache - File f = await DefaultCacheManager().getSingleFile(url,headers: headers); + File f = await DefaultCacheManager().getSingleFile(url, headers: headers); PDFDocument document = PDFDocument(); document._filePath = f.path; try { @@ -77,11 +78,16 @@ class PDFDocument { /// Load specific page /// /// [page] defaults to `1` and must be equal or above it - Future get({int page = 1, final Function(double) onZoomChanged}) async { + Future get( + {int page = 1, final Function(double) onZoomChanged}) async { assert(page > 0); var data = await _channel .invokeMethod('getPage', {'filePath': _filePath, 'pageNumber': page}); - return new PDFPage(data, page,onZoomChanged: onZoomChanged,); + return new PDFPage( + data, + page, + onZoomChanged: onZoomChanged, + ); } // Stream all pages @@ -90,7 +96,11 @@ class PDFDocument { print(i); final data = await _channel .invokeMethod('getPage', {'filePath': _filePath, 'pageNumber': i}); - return new PDFPage(data, 1,onZoomChanged: onZoomChanged,); + return new PDFPage( + data, + 1, + onZoomChanged: onZoomChanged, + ); }).asStream(); } } diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index d933fcdd..99632820 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -13,7 +13,13 @@ class PDFViewer extends StatefulWidget { final bool showPicker; final bool showNavigation; final PDFViewerTooltip tooltip; - final Widget Function(BuildContext, int pageNumber, int totalPages, void Function({int page}) jumpToPage, void Function({int page}) animateToPage,) navigationBuilder; + final Widget Function( + BuildContext, + int pageNumber, + int totalPages, + void Function({int page}) jumpToPage, + void Function({int page}) animateToPage, + ) navigationBuilder; PDFViewer( {Key key, @@ -41,7 +47,7 @@ class _PDFViewerState extends State { final Curve animationCurve = Curves.easeIn; @override - void initState() { + void initState() { super.initState(); _pages = List(widget.document.count); _pageController = PageController(); @@ -63,11 +69,11 @@ class _PDFViewerState extends State { } onZoomChanged(double scale) { - if(scale != 1.0) { + if (scale != 1.0) { setState(() { _swipeEnabled = false; }); - }else{ + } else { setState(() { _swipeEnabled = true; }); @@ -75,13 +81,14 @@ class _PDFViewerState extends State { } _loadPage() async { - if(_pages[_pageNumber-1] != null) return; + if (_pages[_pageNumber - 1] != null) return; setState(() { _isLoading = true; }); - final data = await widget.document.get(page: _pageNumber,onZoomChanged: onZoomChanged); - _pages[_pageNumber-1] = data; - if(mounted) { + final data = await widget.document + .get(page: _pageNumber, onZoomChanged: onZoomChanged); + _pages[_pageNumber - 1] = data; + if (mounted) { setState(() { _isLoading = false; }); @@ -89,15 +96,18 @@ class _PDFViewerState extends State { } _animateToPage({int page}) { - _pageController.animateToPage(page != null ? page : _pageNumber-1, duration: animationDuration, curve: animationCurve); + _pageController.animateToPage(page != null ? page : _pageNumber - 1, + duration: animationDuration, curve: animationCurve); } + _jumpToPage({int page}) { - _pageController.jumpToPage(page != null ? page : _pageNumber-1); + _pageController.jumpToPage(page != null ? page : _pageNumber - 1); } Widget _drawIndicator() { Widget child = GestureDetector( - onTap: widget.showPicker && widget.document.count > 1 ? _pickPage : null, + onTap: + widget.showPicker && widget.document.count > 1 ? _pickPage : null, child: Container( padding: EdgeInsets.only(top: 4.0, left: 16.0, bottom: 4.0, right: 16.0), @@ -152,13 +162,17 @@ class _PDFViewerState extends State { physics: _swipeEnabled ? null : NeverScrollableScrollPhysics(), onPageChanged: (page) { setState(() { - _pageNumber = page+1; + _pageNumber = page + 1; }); _loadPage(); }, controller: _pageController, itemCount: _pages?.length ?? 0, - itemBuilder: (context,index) => _pages[index] == null ? Center(child: CircularProgressIndicator(),) : _pages[index], + itemBuilder: (context, index) => _pages[index] == null + ? Center( + child: CircularProgressIndicator(), + ) + : _pages[index], ), (widget.showIndicator && !_isLoading) ? _drawIndicator() @@ -177,68 +191,78 @@ class _PDFViewerState extends State { : null, floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, bottomNavigationBar: (widget.showNavigation || widget.document.count > 1) - ? widget.navigationBuilder != null ? widget.navigationBuilder( - context, - _pageNumber, - widget.document.count, - _jumpToPage, - _animateToPage, - ) : BottomAppBar( - child: new Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Expanded( - child: IconButton( - icon: Icon(Icons.first_page), - tooltip: widget.tooltip.first, - onPressed: _pageNumber == 1 ? null : () { - _pageNumber = 1; - _jumpToPage(); - }, - ), - ), - Expanded( - child: IconButton( - icon: Icon(Icons.chevron_left), - tooltip: widget.tooltip.previous, - onPressed: _pageNumber == 1 ? null : () { - _pageNumber--; - if (1 > _pageNumber) { - _pageNumber = 1; - } - _animateToPage(); - }, - ), - ), - widget.showPicker - ? Expanded(child: Text('')) - : SizedBox(width: 1), - Expanded( - child: IconButton( - icon: Icon(Icons.chevron_right), - tooltip: widget.tooltip.next, - onPressed: _pageNumber == widget.document.count ? null : () { - _pageNumber++; - if (widget.document.count < _pageNumber) { - _pageNumber = widget.document.count; - } - _animateToPage(); - }, - ), + ? widget.navigationBuilder != null + ? widget.navigationBuilder( + context, + _pageNumber, + widget.document.count, + _jumpToPage, + _animateToPage, + ) + : BottomAppBar( + child: new Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + child: IconButton( + icon: Icon(Icons.first_page), + tooltip: widget.tooltip.first, + onPressed: _pageNumber == 1 + ? null + : () { + _pageNumber = 1; + _jumpToPage(); + }, + ), + ), + Expanded( + child: IconButton( + icon: Icon(Icons.chevron_left), + tooltip: widget.tooltip.previous, + onPressed: _pageNumber == 1 + ? null + : () { + _pageNumber--; + if (1 > _pageNumber) { + _pageNumber = 1; + } + _animateToPage(); + }, + ), + ), + widget.showPicker + ? Expanded(child: Text('')) + : SizedBox(width: 1), + Expanded( + child: IconButton( + icon: Icon(Icons.chevron_right), + tooltip: widget.tooltip.next, + onPressed: _pageNumber == widget.document.count + ? null + : () { + _pageNumber++; + if (widget.document.count < _pageNumber) { + _pageNumber = widget.document.count; + } + _animateToPage(); + }, + ), + ), + Expanded( + child: IconButton( + icon: Icon(Icons.last_page), + tooltip: widget.tooltip.last, + onPressed: _pageNumber == widget.document.count + ? null + : () { + _pageNumber = widget.document.count; + _jumpToPage(); + }, + ), + ), + ], ), - Expanded( - child: IconButton( - icon: Icon(Icons.last_page), - tooltip: widget.tooltip.last, - onPressed: _pageNumber == widget.document.count ? null : () { - _pageNumber = widget.document.count; - _jumpToPage(); - }, - ), - ), - ], - ), - ) + ) : Container(), ); } From cd079c10e72fb38226b6be51e2ea65fc9278c70f Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 13:32:41 +0545 Subject: [PATCH 26/34] version 1.1.0 --- CHANGELOG.md | 6 ++++++ example/pubspec.lock | 2 +- pubspec.yaml | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd876b2b..db82f590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.1.0 +- Removed rxdart dependency +- Upgraded to androidX +- Added support to optional header while loading document from url +- Auto hide picker for 1 page documents + ## 1.0.1 - Swipe control - Zoom scale up to 5.0 diff --git a/example/pubspec.lock b/example/pubspec.lock index ab13b656..ae9fa104 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "1.0.1" + version: "1.1.0" archive: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6dd998a7..56fd9ad8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: advance_pdf_viewer description: A flutter plugin for handling PDF files. Works on both Android & iOS -version: 1.0.1 +version: 1.1.0 homepage: https://github.com/lohanidamodar/pdf_viewer environment: From 8052644fc37eeba4b81497b9f1c5db297bd65b76 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 13:45:23 +0545 Subject: [PATCH 27/34] option to enable/disable swipe navigation --- lib/src/viewer.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index 99632820..b07688bd 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -13,6 +13,7 @@ class PDFViewer extends StatefulWidget { final bool showPicker; final bool showNavigation; final PDFViewerTooltip tooltip; + final bool enableSwipeNavigation; final Widget Function( BuildContext, int pageNumber, @@ -29,6 +30,7 @@ class PDFViewer extends StatefulWidget { this.showIndicator = true, this.showPicker = true, this.showNavigation = true, + this.enableSwipeNavigation = true, this.tooltip = const PDFViewerTooltip(), this.navigationBuilder, this.indicatorPosition = IndicatorPosition.topRight}) @@ -159,7 +161,7 @@ class _PDFViewerState extends State { body: Stack( children: [ PageView.builder( - physics: _swipeEnabled ? null : NeverScrollableScrollPhysics(), + physics: _swipeEnabled && widget.enableSwipeNavigation ? null : NeverScrollableScrollPhysics(), onPageChanged: (page) { setState(() { _pageNumber = page + 1; From 079f09884584f1ef44cc56588bc0db116ccef8c0 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 19:18:18 +0545 Subject: [PATCH 28/34] change scroll direction --- example/lib/main.dart | 3 +++ lib/src/viewer.dart | 3 +++ 2 files changed, 6 insertions(+) diff --git a/example/lib/main.dart b/example/lib/main.dart index e921bd4e..8366417c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -74,6 +74,9 @@ class _MyAppState extends State { ? Center(child: CircularProgressIndicator()) : PDFViewer( document: document, + // uncomment below line to scroll vertically + // scrollDirection: Axis.vertical, + //uncomment below code to replace bottom navigation with your own /* navigationBuilder: (context, page, totalPages, jumpToPage, animateToPage) { diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index b07688bd..2593ee02 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -14,6 +14,7 @@ class PDFViewer extends StatefulWidget { final bool showNavigation; final PDFViewerTooltip tooltip; final bool enableSwipeNavigation; + final Axis scrollDirection; final Widget Function( BuildContext, int pageNumber, @@ -25,6 +26,7 @@ class PDFViewer extends StatefulWidget { PDFViewer( {Key key, @required this.document, + this.scrollDirection, this.indicatorText = Colors.white, this.indicatorBackground = Colors.black54, this.showIndicator = true, @@ -168,6 +170,7 @@ class _PDFViewerState extends State { }); _loadPage(); }, + scrollDirection: widget.scrollDirection ?? Axis.horizontal, controller: _pageController, itemCount: _pages?.length ?? 0, itemBuilder: (context, index) => _pages[index] == null From 83ed3219635b9b72fc0f09b7e04fde93bcf49eb2 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 19:19:38 +0545 Subject: [PATCH 29/34] version 1.1.1 --- CHANGELOG.md | 8 +++++++- example/pubspec.lock | 2 +- pubspec.yaml | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db82f590..433b1e2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ -# 1.1.0 +# Changelog + +## 1.1.1 +- Option to disable swipe navigation `PDFViewer(document: document,scrollDirection: Aixs.vertical)` +- Option to change scroll axis to vertical or horizontal `PDFViewer(document: document,scrollDirection: Aixs.vertical)` + +## 1.1.0 - Removed rxdart dependency - Upgraded to androidX - Added support to optional header while loading document from url diff --git a/example/pubspec.lock b/example/pubspec.lock index ae9fa104..bd45f37a 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "1.1.0" + version: "1.1.1" archive: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 56fd9ad8..6df06e98 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: advance_pdf_viewer description: A flutter plugin for handling PDF files. Works on both Android & iOS -version: 1.1.0 +version: 1.1.1 homepage: https://github.com/lohanidamodar/pdf_viewer environment: From e1131794b653f89bbbf8c7360ec26a7e8179254a Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 19:24:22 +0545 Subject: [PATCH 30/34] format viewer --- lib/src/viewer.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index 2593ee02..11819fee 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -163,7 +163,9 @@ class _PDFViewerState extends State { body: Stack( children: [ PageView.builder( - physics: _swipeEnabled && widget.enableSwipeNavigation ? null : NeverScrollableScrollPhysics(), + physics: _swipeEnabled && widget.enableSwipeNavigation + ? null + : NeverScrollableScrollPhysics(), onPageChanged: (page) { setState(() { _pageNumber = page + 1; From c76d6907ae765428c11d1d5d675bcca34945aacd Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 19:34:30 +0545 Subject: [PATCH 31/34] pub publish workflow --- .github/workflows/publish_pub.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/publish_pub.yml diff --git a/.github/workflows/publish_pub.yml b/.github/workflows/publish_pub.yml new file mode 100644 index 00000000..49446172 --- /dev/null +++ b/.github/workflows/publish_pub.yml @@ -0,0 +1,26 @@ +name: Publish to pub.dev +on: + push: + branches: + - master +jobs: + build: + runs-on: ubuntu-latest + container: + image: google/dart:latest + steps: + - uses: actions/checkout@v1 + - name: Setup credentials + run: | + mkdir -p ~/.pub-cache + cat < ~/.pub-cache/credentials.json + { + "accessToken":"${{ secrets.OAUTH_ACCESS_TOKEN }}", + "refreshToken":"${{ secrets.OAUTH_REFRESH_TOKEN }}", + "tokenEndpoint":"https://accounts.google.com/o/oauth2/token", + "scopes": [ "openid", "https://www.googleapis.com/auth/userinfo.email" ], + "expiration": 1584628470088 + } + EOF + - name: Publish package + run: pub publish -f From c5fe945b66e846fedd0b30e7d5924e75d887687c Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 20:07:35 +0545 Subject: [PATCH 32/34] allow preloading all pages --- example/lib/main.dart | 4 +++- lib/src/document.dart | 18 ++++++++++++++++++ lib/src/viewer.dart | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 8366417c..5f2d3b2a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -74,9 +74,11 @@ class _MyAppState extends State { ? Center(child: CircularProgressIndicator()) : PDFViewer( document: document, + //uncomment below line to preload all pages + // lazyLoad: false, // uncomment below line to scroll vertically // scrollDirection: Axis.vertical, - + //uncomment below code to replace bottom navigation with your own /* navigationBuilder: (context, page, totalPages, jumpToPage, animateToPage) { diff --git a/lib/src/document.dart b/lib/src/document.dart index f973a532..1f764e1e 100644 --- a/lib/src/document.dart +++ b/lib/src/document.dart @@ -12,6 +12,8 @@ class PDFDocument { String _filePath; int count; + List _pages = []; + bool _preloaded = false; /// Load a PDF File from a given File /// @@ -81,6 +83,7 @@ class PDFDocument { Future get( {int page = 1, final Function(double) onZoomChanged}) async { assert(page > 0); + if (_preloaded && _pages.isNotEmpty) return _pages[page - 1]; var data = await _channel .invokeMethod('getPage', {'filePath': _filePath, 'pageNumber': page}); return new PDFPage( @@ -90,6 +93,21 @@ class PDFDocument { ); } + Future preloadPages({final Function(double) onZoomChanged}) async { + int countvar = 1; + await Future.forEach(List(count), (i) async { + final data = await _channel.invokeMethod( + 'getPage', {'filePath': _filePath, 'pageNumber': countvar}); + _pages.add(PDFPage( + data, + countvar, + onZoomChanged: onZoomChanged, + )); + countvar++; + }); + _preloaded = true; + } + // Stream all pages Stream getAll({final Function(double) onZoomChanged}) { return Future.forEach(List(count), (i) async { diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index 11819fee..723395a0 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -15,6 +15,7 @@ class PDFViewer extends StatefulWidget { final PDFViewerTooltip tooltip; final bool enableSwipeNavigation; final Axis scrollDirection; + final bool lazyLoad; final Widget Function( BuildContext, int pageNumber, @@ -27,6 +28,7 @@ class PDFViewer extends StatefulWidget { {Key key, @required this.document, this.scrollDirection, + this.lazyLoad = true, this.indicatorText = Colors.white, this.indicatorBackground = Colors.black54, this.showIndicator = true, @@ -55,6 +57,8 @@ class _PDFViewerState extends State { super.initState(); _pages = List(widget.document.count); _pageController = PageController(); + if (!widget.lazyLoad) + widget.document.preloadPages(onZoomChanged: onZoomChanged); } @override From 670c1b38d87c9ccaac91ab597e17e6c18886a11a Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 19 Mar 2020 20:08:51 +0545 Subject: [PATCH 33/34] version 1.1.2 --- CHANGELOG.md | 3 +++ example/pubspec.lock | 2 +- pubspec.yaml | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 433b1e2c..c9b0c734 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 1.1.2 +- Option to preload all pages in memory `PDFViewer(document: document,lazyLoad: false)` + ## 1.1.1 - Option to disable swipe navigation `PDFViewer(document: document,scrollDirection: Aixs.vertical)` - Option to change scroll axis to vertical or horizontal `PDFViewer(document: document,scrollDirection: Aixs.vertical)` diff --git a/example/pubspec.lock b/example/pubspec.lock index bd45f37a..cc97528d 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "1.1.1" + version: "1.1.2" archive: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6df06e98..02c4eb07 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: advance_pdf_viewer description: A flutter plugin for handling PDF files. Works on both Android & iOS -version: 1.1.1 +version: 1.1.2 homepage: https://github.com/lohanidamodar/pdf_viewer environment: From baeda50450c2e192787d3088778c58bfebe2375f Mon Sep 17 00:00:00 2001 From: "brandon.maness" Date: Fri, 20 Mar 2020 08:58:08 -0500 Subject: [PATCH 34/34] update podspec filename --- ...ter_plugin_pdf_viewer.podspec => advance_pdf_viewer.podspec} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename ios/{flutter_plugin_pdf_viewer.podspec => advance_pdf_viewer.podspec} (93%) diff --git a/ios/flutter_plugin_pdf_viewer.podspec b/ios/advance_pdf_viewer.podspec similarity index 93% rename from ios/flutter_plugin_pdf_viewer.podspec rename to ios/advance_pdf_viewer.podspec index 4e1f42be..5786babf 100644 --- a/ios/flutter_plugin_pdf_viewer.podspec +++ b/ios/advance_pdf_viewer.podspec @@ -2,7 +2,7 @@ # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html # Pod::Spec.new do |s| - s.name = 'flutter_plugin_pdf_viewer' + s.name = 'advance_pdf_viewer' s.version = '1.0.5' s.summary = 'Allows you to generate PNG's of specified pages from a provided PDF file source.' s.description = <<-DESC