From 4898ea87fd7518a90d1211e47b44c3429c1aaaf0 Mon Sep 17 00:00:00 2001 From: allanwolski Date: Tue, 3 Sep 2019 17:37:54 -0300 Subject: [PATCH 01/45] Change to use NSCachesDirectory --- ios/Classes/FlutterPluginPdfViewerPlugin.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ios/Classes/FlutterPluginPdfViewerPlugin.m b/ios/Classes/FlutterPluginPdfViewerPlugin.m index 2345bad6..5919a468 100644 --- a/ios/Classes/FlutterPluginPdfViewerPlugin.m +++ b/ios/Classes/FlutterPluginPdfViewerPlugin.m @@ -39,9 +39,9 @@ -(NSString *)getNumberOfPages:(NSString *)url } CGPDFDocumentRef SourcePDFDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)sourcePDFUrl); size_t numberOfPages = CGPDFDocumentGetNumberOfPages(SourcePDFDocument); - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *documentsDirectory = [paths objectAtIndex:0]; - NSString *filePathAndDirectory = [documentsDirectory stringByAppendingPathComponent:kDirectory]; + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + NSString *temporaryDirectory = [paths objectAtIndex:0]; + NSString *filePathAndDirectory = [temporaryDirectory stringByAppendingPathComponent:kDirectory]; NSError *error; // Clear cache folder @@ -76,9 +76,9 @@ -(NSString*)getPage:(NSString *)url ofPage:(size_t)pageNumber } CGPDFDocumentRef SourcePDFDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)sourcePDFUrl); size_t numberOfPages = CGPDFDocumentGetNumberOfPages(SourcePDFDocument); - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *documentsDirectory = [paths objectAtIndex:0]; - NSString *filePathAndDirectory = [documentsDirectory stringByAppendingPathComponent:kDirectory]; + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + NSString *temporaryDirectory = [paths objectAtIndex:0]; + NSString *filePathAndDirectory = [temporaryDirectory stringByAppendingPathComponent:kDirectory]; NSError *error; if (pageNumber > numberOfPages) { @@ -96,7 +96,7 @@ -(NSString*)getPage:(NSString *)url ofPage:(size_t)pageNumber CGPDFPageRef SourcePDFPage = CGPDFDocumentGetPage(SourcePDFDocument, pageNumber); CGPDFPageRetain(SourcePDFPage); NSString *relativeOutputFilePath = [NSString stringWithFormat:@"%@/%@-%d.png", kDirectory, kFileName, (int)pageNumber]; - NSString *imageFilePath = [documentsDirectory stringByAppendingPathComponent:relativeOutputFilePath]; + NSString *imageFilePath = [temporaryDirectory stringByAppendingPathComponent:relativeOutputFilePath]; CGRect sourceRect = CGPDFPageGetBoxRect(SourcePDFPage, kCGPDFMediaBox); UIGraphicsBeginPDFContextToFile(imageFilePath, sourceRect, nil); // Calculate resolution From 6e60782af7281383a4fd9ccf71fc9f86eb4ae50a Mon Sep 17 00:00:00 2001 From: Wendell Farley Date: Thu, 12 Dec 2019 15:48:26 -0600 Subject: [PATCH 02/45] 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 03/45] 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 04/45] 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 05/45] 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 06/45] 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 07/45] 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 08/45] 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 09/45] 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 10/45] 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 11/45] 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 12/45] 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 13/45] 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 14/45] 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 15/45] 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 16/45] 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 17/45] 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 18/45] 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 19/45] 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 20/45] 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 21/45] 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 22/45] 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 23/45] 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 24/45] 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 25/45] 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 26/45] 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 27/45] 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 28/45] 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 29/45] 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 30/45] 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 31/45] 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 32/45] 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 33/45] 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 34/45] 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 35/45] 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 From 020aa50455088fedcbc90c6d569e350112e4b9b1 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sat, 21 Mar 2020 15:38:30 +0545 Subject: [PATCH 36/45] pub version in readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4ce19bf9..e294b463 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ A flutter plugin for handling PDF files. Works on both Android & iOS. Originally forked from (https://github.com/CrossPT/flutter_plugin_pdf_viewer). +[![Pub Package](https://img.shields.io/pub/v/advance_pdf_viewer.svg?style=flat-square)](https://pub.dartlang.org/packages/advance_pdf_viewer) + + ## Installation Add *advance_pdf_viewer* as a dependency in [your pubspec.yaml file](https://flutter.io/platform-plugins/). From da9305ef1bb9728860461e49412cc0880ef64bfb Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 25 Mar 2020 12:58:07 +0545 Subject: [PATCH 37/45] allow passing in controller --- 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 723395a0..0681c8fb 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -16,6 +16,7 @@ class PDFViewer extends StatefulWidget { final bool enableSwipeNavigation; final Axis scrollDirection; final bool lazyLoad; + final PageController controller; final Widget Function( BuildContext, int pageNumber, @@ -37,6 +38,7 @@ class PDFViewer extends StatefulWidget { this.enableSwipeNavigation = true, this.tooltip = const PDFViewerTooltip(), this.navigationBuilder, + this.controller, this.indicatorPosition = IndicatorPosition.topRight}) : super(key: key); @@ -56,7 +58,7 @@ class _PDFViewerState extends State { void initState() { super.initState(); _pages = List(widget.document.count); - _pageController = PageController(); + _pageController = widget.controller ?? PageController(); if (!widget.lazyLoad) widget.document.preloadPages(onZoomChanged: onZoomChanged); } From 165225086ee12ae54f971ad75e8f0e84a2bcdce1 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 25 Mar 2020 12:59:09 +0545 Subject: [PATCH 38/45] changelog and pubspec version upgrade --- 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 c9b0c734..1ff31e11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 1.1.3 +- Option to pass in controller `PDFViewer(document: document,controller: PageController())` that you can use to control the pageview rendering the PDF pages. + ## 1.1.2 - Option to preload all pages in memory `PDFViewer(document: document,lazyLoad: false)` diff --git a/example/pubspec.lock b/example/pubspec.lock index cc97528d..fed15724 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "1.1.2" + version: "1.1.3" archive: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 02c4eb07..40522e57 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.2 +version: 1.1.3 homepage: https://github.com/lohanidamodar/pdf_viewer environment: From e2d2e6d39adc141a001573de879c873828bec832 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sat, 28 Mar 2020 13:33:28 +0545 Subject: [PATCH 39/45] version and changelog --- CHANGELOG.md | 4 ++++ example/pubspec.lock | 2 +- pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ff31e11..7d7d1fbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.1.4 +* Proper android cache cleanup +* iOS build fix + ## 1.1.3 - Option to pass in controller `PDFViewer(document: document,controller: PageController())` that you can use to control the pageview rendering the PDF pages. diff --git a/example/pubspec.lock b/example/pubspec.lock index fed15724..9fd243c3 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "1.1.3" + version: "1.1.4" archive: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index e042a691..000dbe6c 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.3 +version: 1.1.4 homepage: https://github.com/lohanidamodar/pdf_viewer environment: From 7ab33f494332c9fe73e31c12af1ea9bf6f49dde8 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sat, 28 Mar 2020 22:51:01 +0545 Subject: [PATCH 40/45] fixing initial page using page controller --- lib/src/viewer.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index 0681c8fb..55a11d2e 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -47,7 +47,7 @@ class PDFViewer extends StatefulWidget { class _PDFViewerState extends State { bool _isLoading = true; - int _pageNumber = 1; + int _pageNumber; bool _swipeEnabled = true; List _pages; PageController _pageController; @@ -59,6 +59,7 @@ class _PDFViewerState extends State { super.initState(); _pages = List(widget.document.count); _pageController = widget.controller ?? PageController(); + _pageNumber = _pageController.initialPage+1; if (!widget.lazyLoad) widget.document.preloadPages(onZoomChanged: onZoomChanged); } @@ -66,7 +67,7 @@ class _PDFViewerState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - _pageNumber = 1; + _pageNumber = _pageController.initialPage+1; _isLoading = true; _pages = List(widget.document.count); // _loadAllPages(); From 6bcfbbdcbdf627a0c688ed541deae9278cc13f34 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sat, 28 Mar 2020 22:52:30 +0545 Subject: [PATCH 41/45] pubspec version upgrade and changelog --- 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 7d7d1fbf..fc909b30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 1.1.4 +* Page controller initial page setting fixed (making able to set initially loaded page) + ## 1.1.4 * Proper android cache cleanup * iOS build fix diff --git a/example/pubspec.lock b/example/pubspec.lock index 9fd243c3..799f8eea 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "1.1.4" + version: "1.1.5" archive: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 000dbe6c..fa13974a 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.4 +version: 1.1.5 homepage: https://github.com/lohanidamodar/pdf_viewer environment: From ff52de270cdefd95dcf7236c769d7f9fd32aac34 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 29 Mar 2020 08:03:48 +0545 Subject: [PATCH 42/45] expose zoom widget parameters --- example/lib/main.dart | 1 + lib/src/document.dart | 26 +++++++++++++++++++++++--- lib/src/page.dart | 22 +++++++++++++++++----- lib/src/viewer.dart | 33 +++++++++++++++++++++++++++------ 4 files changed, 68 insertions(+), 14 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 5f2d3b2a..d971b94a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -74,6 +74,7 @@ class _MyAppState extends State { ? Center(child: CircularProgressIndicator()) : PDFViewer( document: document, + zoomSteps: 1, //uncomment below line to preload all pages // lazyLoad: false, // uncomment below line to scroll vertically diff --git a/lib/src/document.dart b/lib/src/document.dart index 1f764e1e..8de8eeda 100644 --- a/lib/src/document.dart +++ b/lib/src/document.dart @@ -80,8 +80,14 @@ 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, + final int zoomSteps, + final double minScale, + final double maxScale, + final double panLimit, + }) async { assert(page > 0); if (_preloaded && _pages.isNotEmpty) return _pages[page - 1]; var data = await _channel @@ -90,10 +96,20 @@ class PDFDocument { data, page, onZoomChanged: onZoomChanged, + zoomSteps: zoomSteps, + minScale: minScale, + maxScale: maxScale, + panLimit: panLimit, ); } - Future preloadPages({final Function(double) onZoomChanged}) async { + Future preloadPages({ + final Function(double) onZoomChanged, + final int zoomSteps, + final double minScale, + final double maxScale, + final double panLimit, + }) async { int countvar = 1; await Future.forEach(List(count), (i) async { final data = await _channel.invokeMethod( @@ -102,6 +118,10 @@ class PDFDocument { data, countvar, onZoomChanged: onZoomChanged, + zoomSteps: zoomSteps, + minScale: minScale, + maxScale: maxScale, + panLimit: panLimit, )); countvar++; }); diff --git a/lib/src/page.dart b/lib/src/page.dart index b8cfb22b..50b34f68 100644 --- a/lib/src/page.dart +++ b/lib/src/page.dart @@ -8,7 +8,19 @@ class PDFPage extends StatefulWidget { final String imgPath; final int num; final Function(double) onZoomChanged; - PDFPage(this.imgPath, this.num, {this.onZoomChanged}); + final int zoomSteps; + final double minScale; + final double maxScale; + final double panLimit; + PDFPage( + this.imgPath, + this.num, { + this.onZoomChanged, + this.zoomSteps = 3, + this.minScale = 1.0, + this.maxScale = 5.0, + this.panLimit = 1.0, + }); @override _PDFPageState createState() => _PDFPageState(); @@ -45,10 +57,10 @@ class _PDFPageState extends State { decoration: null, child: ZoomableWidget( onZoomChanged: widget.onZoomChanged, - zoomSteps: 3, - minScale: 1.0, - panLimit: 1.0, - maxScale: 5.0, + zoomSteps: widget.zoomSteps ?? 3, + minScale: widget.minScale ?? 1.0, + panLimit: widget.panLimit ?? 1.0, + maxScale: widget.maxScale ?? 5.0, child: Image(image: provider), )); } diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index 55a11d2e..7d5a5f79 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -17,6 +17,11 @@ class PDFViewer extends StatefulWidget { final Axis scrollDirection; final bool lazyLoad; final PageController controller; + final int zoomSteps; + final double minScale; + final double maxScale; + final double panLimit; + final Widget Function( BuildContext, int pageNumber, @@ -39,7 +44,11 @@ class PDFViewer extends StatefulWidget { this.tooltip = const PDFViewerTooltip(), this.navigationBuilder, this.controller, - this.indicatorPosition = IndicatorPosition.topRight}) + this.indicatorPosition = IndicatorPosition.topRight, + this.zoomSteps, + this.minScale, + this.maxScale, + this.panLimit}) : super(key: key); _PDFViewerState createState() => _PDFViewerState(); @@ -59,15 +68,21 @@ class _PDFViewerState extends State { super.initState(); _pages = List(widget.document.count); _pageController = widget.controller ?? PageController(); - _pageNumber = _pageController.initialPage+1; + _pageNumber = _pageController.initialPage + 1; if (!widget.lazyLoad) - widget.document.preloadPages(onZoomChanged: onZoomChanged); + widget.document.preloadPages( + onZoomChanged: onZoomChanged, + zoomSteps: widget.zoomSteps, + minScale: widget.minScale, + maxScale: widget.maxScale, + panLimit: widget.panLimit, + ); } @override void didChangeDependencies() { super.didChangeDependencies(); - _pageNumber = _pageController.initialPage+1; + _pageNumber = _pageController.initialPage + 1; _isLoading = true; _pages = List(widget.document.count); // _loadAllPages(); @@ -96,8 +111,14 @@ class _PDFViewerState extends State { setState(() { _isLoading = true; }); - final data = await widget.document - .get(page: _pageNumber, onZoomChanged: onZoomChanged); + final data = await widget.document.get( + page: _pageNumber, + onZoomChanged: onZoomChanged, + zoomSteps: widget.zoomSteps, + minScale: widget.minScale, + maxScale: widget.maxScale, + panLimit: widget.panLimit, + ); _pages[_pageNumber - 1] = data; if (mounted) { setState(() { From 851ad1675345e7ef6a2c8b58bb325893f879402f Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 29 Mar 2020 08:06:05 +0545 Subject: [PATCH 43/45] version upgrade and changelog --- CHANGELOG.md | 5 ++++- example/pubspec.lock | 2 +- pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc909b30..00591d46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog -## 1.1.4 +## 1.1.6 +* Exposing `ZoomableWidget` from [flutter_advanced_networkimage](https://pub.dartlang.org/packages/flutter_advanced_networkimage) parameters (minScale, zoomSteps, maxScale,panLimit) + +## 1.1.5 * Page controller initial page setting fixed (making able to set initially loaded page) ## 1.1.4 diff --git a/example/pubspec.lock b/example/pubspec.lock index 799f8eea..1c48553f 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "1.1.5" + version: "1.1.6" archive: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index fa13974a..241ac1e1 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.5 +version: 1.1.6 homepage: https://github.com/lohanidamodar/pdf_viewer environment: From 68e1aa897435244beb2395d6a358c331bf12f905 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 11 Aug 2020 22:27:47 +0545 Subject: [PATCH 44/45] updated to work with flutter 1.20+ --- CHANGELOG.md | 3 + example/pubspec.lock | 154 +++++++------- example/pubspec.yaml | 4 +- lib/src/page.dart | 2 +- lib/src/zoomable_widget.dart | 392 +++++++++++++++++++++++++++++++++++ pubspec.lock | 113 ++++++---- pubspec.yaml | 10 +- 7 files changed, 547 insertions(+), 131 deletions(-) create mode 100644 lib/src/zoomable_widget.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 00591d46..e300dc76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 1.2.0 +* updated to work with Flutter 1.20+ + ## 1.1.6 * Exposing `ZoomableWidget` from [flutter_advanced_networkimage](https://pub.dartlang.org/packages/flutter_advanced_networkimage) parameters (minScale, zoomSteps, maxScale,panLimit) diff --git a/example/pubspec.lock b/example/pubspec.lock index 1c48553f..ff4b6e5d 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -2,54 +2,54 @@ # See https://dart.dev/tools/pub/glossary#lockfile packages: advance_pdf_viewer: - dependency: "direct dev" + dependency: "direct main" description: path: ".." relative: true source: path - version: "1.1.6" - archive: + version: "1.2.0" + async: dependency: transitive description: - name: archive + name: async url: "https://pub.dartlang.org" source: hosted - version: "2.0.11" - args: + version: "2.4.2" + boolean_selector: dependency: transitive description: - name: args + name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.5.2" - async: + version: "2.0.0" + characters: dependency: transitive description: - name: async + name: characters url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" - boolean_selector: + version: "1.0.0" + charcode: dependency: transitive description: - name: boolean_selector + name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" - charcode: + version: "1.1.3" + clock: dependency: transitive description: - name: charcode + name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.0.1" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.14.13" convert: dependency: transitive description: @@ -71,32 +71,32 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.2" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_advanced_networkimage: + fake_async: dependency: transitive description: - name: flutter_advanced_networkimage + name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "0.7.0" - flutter_cache_manager: + version: "1.1.0" + file: dependency: transitive description: - name: flutter_cache_manager + name: file url: "https://pub.dartlang.org" source: hosted - version: "1.1.3" - flutter_svg: + version: "5.2.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_cache_manager: dependency: transitive description: - name: flutter_svg + name: flutter_cache_manager url: "https://pub.dartlang.org" source: hosted - version: "0.17.3+1" + version: "1.4.1" flutter_test: dependency: "direct dev" description: flutter @@ -108,7 +108,7 @@ packages: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.12.0+1" + version: "0.12.2" http_parser: dependency: transitive description: @@ -116,27 +116,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.3" - image: + infinite_listview: dependency: transitive description: - name: image + name: infinite_listview url: "https://pub.dartlang.org" source: hosted - version: "2.1.4" - infinite_listview: + version: "1.0.1+1" + intl: dependency: transitive description: - name: infinite_listview + name: intl url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "0.16.1" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.8" meta: dependency: transitive description: @@ -150,35 +150,28 @@ packages: name: numberpicker url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" - path_drawing: - dependency: transitive - description: - name: path_drawing - url: "https://pub.dartlang.org" - source: hosted - version: "0.4.1" - path_parsing: + version: "1.7.0" + path_provider: dependency: transitive description: - name: path_parsing + name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" - path_provider: + version: "1.6.11" + path_provider_linux: dependency: transitive description: - name: path_provider + name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "1.6.5" + version: "0.0.1+2" path_provider_macos: dependency: transitive description: @@ -199,14 +192,7 @@ packages: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" + version: "1.9.0" platform: dependency: transitive description: @@ -221,13 +207,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.2" - quiver: + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.13" + rxdart: dependency: transitive description: - name: quiver + name: rxdart url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "0.24.1" sky_engine: dependency: transitive description: flutter @@ -239,21 +232,28 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.7.0" sqflite: dependency: transitive description: name: sqflite url: "https://pub.dartlang.org" source: hosted - version: "1.1.3" + version: "1.3.1" + sqflite_common: + dependency: transitive + description: + name: sqflite_common + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2+1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.9.5" stream_channel: dependency: transitive description: @@ -288,21 +288,21 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.11" + version: "0.2.17" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.2.0" uuid: dependency: transitive description: name: uuid url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.2.0" vector_math: dependency: transitive description: @@ -310,13 +310,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" - xml: + xdg_directories: dependency: transitive description: - name: xml + name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "3.5.0" + version: "0.1.0" sdks: - dart: ">=2.4.0 <3.0.0" - flutter: ">=1.10.0 <2.0.0" + dart: ">=2.9.0-14.0.dev <3.0.0" + flutter: ">=1.12.13+hotfix.5 <2.0.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 96dfe4f2..db5eb5c7 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -12,13 +12,13 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.2 + advance_pdf_viewer: + path: ../ dev_dependencies: flutter_test: sdk: flutter - advance_pdf_viewer: - path: ../ flutter: uses-material-design: true diff --git a/lib/src/page.dart b/lib/src/page.dart index 50b34f68..a777c2a1 100644 --- a/lib/src/page.dart +++ b/lib/src/page.dart @@ -1,8 +1,8 @@ import 'dart:io'; import 'dart:ui'; +import 'package:advance_pdf_viewer/src/zoomable_widget.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter/painting.dart'; -import 'package:flutter_advanced_networkimage/zoomable.dart'; class PDFPage extends StatefulWidget { final String imgPath; diff --git a/lib/src/zoomable_widget.dart b/lib/src/zoomable_widget.dart new file mode 100644 index 00000000..ee13468e --- /dev/null +++ b/lib/src/zoomable_widget.dart @@ -0,0 +1,392 @@ +/// originally from https://github.com/mchome/flutter_advanced_networkimage +import 'dart:math'; + +import 'package:flutter/widgets.dart'; + +class ZoomableWidget extends StatefulWidget { + ZoomableWidget({ + Key key, + this.minScale: 0.7, + this.maxScale: 1.4, + this.initialScale: 1.0, + this.initialOffset: Offset.zero, + this.initialRotation: 0.0, + this.enableZoom: true, + this.panLimit: 1.0, + this.singleFingerPan: true, + this.multiFingersPan: true, + this.enableRotate: false, + this.child, + this.onTap, + this.zoomSteps: 0, + this.autoCenter: false, + this.bounceBackBoundary: true, + this.enableFling: true, + this.flingFactor: 1.0, + this.onZoomChanged, + this.resetDuration: const Duration(milliseconds: 250), + this.resetCurve: Curves.easeInOut, + }) : assert(minScale != null), + assert(maxScale != null), + assert(initialScale != null), + assert(initialOffset != null), + assert(initialRotation != null), + assert(enableZoom != null), + assert(panLimit != null), + assert(singleFingerPan != null), + assert(multiFingersPan != null), + assert(enableRotate != null), + assert(zoomSteps != null), + assert(autoCenter != null), + assert(bounceBackBoundary != null), + assert(enableFling != null), + assert(flingFactor != null); + + /// The minimum size for scaling. + final double minScale; + + /// The maximum size for scaling. + final double maxScale; + + /// The initial scale. + final double initialScale; + + /// The initial offset. + final Offset initialOffset; + + /// The initial rotation. + final double initialRotation; + + /// Allow zooming the child widget. + final bool enableZoom; + + /// Allow panning with one finger. + final bool singleFingerPan; + + /// Allow panning with more than one finger. + final bool multiFingersPan; + + /// Allow rotating the [image]. + final bool enableRotate; + + /// Create a boundary with the factor. + final double panLimit; + + /// The child widget that is display. + final Widget child; + + /// Tap callback for this widget. + final VoidCallback onTap; + + /// Allow users to zoom with double tap steps by steps. + final int zoomSteps; + + /// Center offset when zooming to minimum scale. + final bool autoCenter; + + /// Enable the bounce-back boundary. + final bool bounceBackBoundary; + + /// Allow fling child widget after panning. + final bool enableFling; + + /// Greater value create greater fling distance. + final double flingFactor; + + /// When the scale value changed, the callback will be invoked. + final ValueChanged onZoomChanged; + + /// The duration of reset animation. + final Duration resetDuration; + + /// The curve of reset animation. + final Curve resetCurve; + + @override + _ZoomableWidgetState createState() => _ZoomableWidgetState(); +} + +class _ZoomableWidgetState extends State { + final GlobalKey _key = GlobalKey(); + + double _zoom = 1.0; + double _previousZoom = 1.0; + Offset _previousPanOffset = Offset.zero; + Offset _pan = Offset.zero; + Offset _zoomOriginOffset = Offset.zero; + double _rotation = 0.0; + double _previousRotation = 0.0; + + Size _childSize = Size.zero; + Size _containerSize = Size.zero; + + Duration _duration = const Duration(milliseconds: 100); + Curve _curve = Curves.easeOut; + + @override + void initState() { + super.initState(); + _zoom = widget.initialScale; + _pan = widget.initialOffset; + _rotation = widget.initialRotation; + } + + void _onScaleStart(ScaleStartDetails details) { + if (_childSize == Size.zero) { + final RenderBox renderbox = _key.currentContext.findRenderObject(); + _childSize = renderbox.size; + } + setState(() { + _zoomOriginOffset = details.focalPoint; + _previousPanOffset = _pan; + _previousZoom = _zoom; + _previousRotation = _rotation; + }); + } + + void _onScaleUpdate(ScaleUpdateDetails details) { + Size boundarySize = _boundarySize; + + Size _marginSize = const Size(100.0, 100.0); + + _duration = const Duration(milliseconds: 50); + _curve = Curves.easeOut; + + setState(() { + if (widget.enableRotate) + _rotation = (_previousRotation + details.rotation).clamp(-pi, pi); + if (widget.enableZoom && details.scale != 1.0) { + _zoom = (_previousZoom * details.scale) + .clamp(widget.minScale, widget.maxScale); + if (widget.onZoomChanged != null) widget.onZoomChanged(_zoom); + } + }); + + if ((widget.singleFingerPan && details.scale == 1.0) || + (widget.multiFingersPan && details.scale != 1.0)) { + Offset _panRealOffset = (details.focalPoint - + _zoomOriginOffset + + _previousPanOffset * _previousZoom) / + _zoom; + + if (widget.panLimit == 0.0) { + _pan = _panRealOffset; + } else { + Offset _baseOffset = Offset( + _panRealOffset.dx + .clamp(-boundarySize.width / 2, boundarySize.width / 2), + _panRealOffset.dy + .clamp(-boundarySize.height / 2, boundarySize.height / 2), + ); + + Offset _marginOffset = _panRealOffset - _baseOffset; + double _widthFactor = sqrt(_marginOffset.dx.abs()) / _marginSize.width; + double _heightFactor = + sqrt(_marginOffset.dy.abs()) / _marginSize.height; + _marginOffset = Offset( + _marginOffset.dx * _widthFactor * 2, + _marginOffset.dy * _heightFactor * 2, + ); + _pan = _baseOffset + _marginOffset; + } + setState(() {}); + } + } + + void _onScaleEnd(ScaleEndDetails details) { + Size boundarySize = _boundarySize; + + _duration = widget.resetDuration; + _curve = widget.resetCurve; + + final Offset velocity = details.velocity.pixelsPerSecond; + final double magnitude = velocity.distance; + if (magnitude > 800.0 * _zoom && widget.enableFling) { + final Offset direction = velocity / magnitude; + final double distance = (Offset.zero & context.size).shortestSide; + final Offset endOffset = + _pan + direction * distance * widget.flingFactor * 0.5; + _pan = Offset( + endOffset.dx.clamp(-boundarySize.width / 2, boundarySize.width / 2), + endOffset.dy.clamp(-boundarySize.height / 2, boundarySize.height / 2), + ); + } + Offset _clampedOffset = Offset( + _pan.dx.clamp(-boundarySize.width / 2, boundarySize.width / 2), + _pan.dy.clamp(-boundarySize.height / 2, boundarySize.height / 2), + ); + if (_zoom == widget.minScale && widget.autoCenter) { + _clampedOffset = Offset.zero; + } + setState(() => _pan = _clampedOffset); + } + + Size get _boundarySize { + Size _boundarySize = Size( + (_containerSize.width == _childSize.width) + ? (_containerSize.width - _childSize.width / _zoom).abs() + : (_containerSize.width - _childSize.width * _zoom).abs() / _zoom, + (_containerSize.height == _childSize.height) + ? (_containerSize.height - _childSize.height / _zoom).abs() + : (_containerSize.height - _childSize.height * _zoom).abs() / + _zoom, + ) * + widget.panLimit; + + return _boundarySize; + } + + void _handleDoubleTap() { + double _stepLength = 0.0; + + _duration = widget.resetDuration; + _curve = widget.resetCurve; + + if (widget.zoomSteps > 0) + _stepLength = (widget.maxScale - 1.0) / widget.zoomSteps; + + double _tmpZoom = _zoom + _stepLength; + if (_tmpZoom > widget.maxScale || _stepLength == 0.0) _tmpZoom = 1.0; + + setState(() { + _zoom = _tmpZoom; + if (widget.onZoomChanged != null) widget.onZoomChanged(_zoom); + _pan = Offset.zero; + _rotation = 0.0; + _previousZoom = _tmpZoom; + if (_tmpZoom == 1.0) { + _zoomOriginOffset = Offset.zero; + _previousPanOffset = Offset.zero; + } + }); + } + + @override + Widget build(BuildContext context) { + if (widget.child == null) return SizedBox(); + + return CustomMultiChildLayout( + delegate: _ZoomableWidgetLayout(), + children: [ + LayoutId( + id: _ZoomableWidgetLayout.painter, + child: _ZoomableChild( + duration: _duration, + curve: _curve, + zoom: _zoom, + panOffset: _pan, + rotation: _rotation, + child: LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + _containerSize = + Size(constraints.maxWidth, constraints.maxHeight); + return Center( + child: Container(key: _key, child: widget.child), + ); + }, + ), + ), + ), + LayoutId( + id: _ZoomableWidgetLayout.gestureContainer, + child: GestureDetector( + child: Container(color: Color(0)), + onScaleStart: _onScaleStart, + onScaleUpdate: _onScaleUpdate, + onScaleEnd: widget.bounceBackBoundary ? _onScaleEnd : null, + onDoubleTap: _handleDoubleTap, + onTap: widget.onTap, + ), + ), + ], + ); + } +} + +class _ZoomableWidgetLayout extends MultiChildLayoutDelegate { + _ZoomableWidgetLayout(); + + static final String gestureContainer = 'gesturecontainer'; + static final String painter = 'painter'; + + @override + void performLayout(Size size) { + layoutChild(gestureContainer, + BoxConstraints.tightFor(width: size.width, height: size.height)); + positionChild(gestureContainer, Offset.zero); + layoutChild(painter, + BoxConstraints.tightFor(width: size.width, height: size.height)); + positionChild(painter, Offset.zero); + } + + @override + bool shouldRelayout(_ZoomableWidgetLayout oldDelegate) => false; +} + +class _ZoomableChild extends ImplicitlyAnimatedWidget { + const _ZoomableChild({ + Duration duration, + Curve curve = Curves.linear, + @required this.zoom, + @required this.panOffset, + @required this.rotation, + @required this.child, + }) : super(duration: duration, curve: curve); + + final double zoom; + final Offset panOffset; + final double rotation; + final Widget child; + + @override + ImplicitlyAnimatedWidgetState createState() => + _ZoomableChildState(); +} + +class _ZoomableChildState extends AnimatedWidgetBaseState<_ZoomableChild> { + DoubleTween _zoom; + OffsetTween _panOffset; + // OffsetTween _zoomOriginOffset; + DoubleTween _rotation; + + @override + void forEachTween(visitor) { + _zoom = visitor( + _zoom, widget.zoom, (dynamic value) => DoubleTween(begin: value)); + _panOffset = visitor(_panOffset, widget.panOffset, + (dynamic value) => OffsetTween(begin: value)); + _rotation = visitor(_rotation, widget.rotation, + (dynamic value) => DoubleTween(begin: value)); + } + + @override + Widget build(BuildContext context) { + return Transform( + alignment: Alignment.center, + origin: Offset(-_panOffset.evaluate(animation).dx, + -_panOffset.evaluate(animation).dy), + transform: Matrix4.identity() + ..translate(_panOffset.evaluate(animation).dx, + _panOffset.evaluate(animation).dy) + ..scale(_zoom.evaluate(animation), _zoom.evaluate(animation)), + child: Transform.rotate( + angle: _rotation.evaluate(animation), + child: widget.child, + ), + ); + } +} + +class DoubleTween extends Tween { + DoubleTween({double begin, double end}) : super(begin: begin, end: end); + + @override + double lerp(double t) => (begin + (end - begin) * t); +} + +class OffsetTween extends Tween { + OffsetTween({Offset begin, Offset end}) : super(begin: begin, end: end); + + @override + Offset lerp(double t) => (begin + (end - begin) * t); +} diff --git a/pubspec.lock b/pubspec.lock index c771fa22..958076bd 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -8,6 +8,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.2.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" charcode: dependency: transitive description: @@ -15,13 +22,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.2" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.14.13" convert: dependency: transitive description: @@ -36,32 +50,25 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.6" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "5.2.1" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" - flutter_advanced_networkimage: - dependency: "direct main" - description: - name: flutter_advanced_networkimage - url: "https://pub.dartlang.org" - source: hosted - version: "0.7.0" flutter_cache_manager: dependency: "direct main" description: name: flutter_cache_manager url: "https://pub.dartlang.org" source: hosted - version: "1.1.3" - flutter_svg: - dependency: transitive - description: - name: flutter_svg - url: "https://pub.dartlang.org" - source: hosted - version: "0.17.3+1" + version: "1.4.1" http: dependency: transitive description: @@ -82,7 +89,14 @@ packages: name: infinite_listview url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.0.1+1" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.1" meta: dependency: transitive description: @@ -96,7 +110,7 @@ packages: name: numberpicker url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" path: dependency: transitive description: @@ -104,27 +118,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.6.4" - path_drawing: - dependency: transitive + path_provider: + dependency: "direct main" description: - name: path_drawing + name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "0.4.1" - path_parsing: + version: "1.6.11" + path_provider_linux: dependency: transitive description: - name: path_parsing - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.4" - path_provider: - dependency: "direct main" - description: - name: path_provider + name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "1.6.5" + version: "0.0.1+2" path_provider_macos: dependency: transitive description: @@ -146,13 +153,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" platform: dependency: transitive description: @@ -167,6 +167,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.2" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.13" + rxdart: + dependency: transitive + description: + name: rxdart + url: "https://pub.dartlang.org" + source: hosted + version: "0.24.1" sky_engine: dependency: transitive description: flutter @@ -185,7 +199,14 @@ packages: name: sqflite url: "https://pub.dartlang.org" source: hosted - version: "1.1.6+1" + version: "1.3.1" + sqflite_common: + dependency: transitive + description: + name: sqflite_common + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2+1" string_scanner: dependency: transitive description: @@ -213,7 +234,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.2.0" uuid: dependency: transitive description: @@ -228,13 +249,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" - xml: + xdg_directories: dependency: transitive description: - name: xml + name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "3.5.0" + version: "0.1.0" sdks: - dart: ">=2.4.0 <3.0.0" - flutter: ">=1.10.0 <2.0.0" + dart: ">=2.9.0-14.0.dev <3.0.0" + flutter: ">=1.12.13+hotfix.5 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 241ac1e1..5a00a5e7 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.6 +version: 1.2.0 homepage: https://github.com/lohanidamodar/pdf_viewer environment: @@ -9,12 +9,12 @@ environment: dependencies: flutter: sdk: flutter - flutter_cache_manager: ^1.1.3 - path_provider: ^1.6.5 - numberpicker: ^1.2.0 - flutter_advanced_networkimage: ^0.7.0 + flutter_cache_manager: ^1.4.1 + path_provider: ^1.6.11 + numberpicker: ^1.2.1 flutter: plugin: androidPackage: pt.tribeiro.flutter_plugin_pdf_viewer pluginClass: FlutterPluginPdfViewerPlugin + From 65ba4e3c51e9ceb34352a38177abe55a859033f6 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 11 Aug 2020 22:40:01 +0545 Subject: [PATCH 45/45] updated pubspec to match latest updates --- example/pubspec.lock | 2 +- pubspec.lock | 2 +- pubspec.yaml | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index ff4b6e5d..d22b4e91 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -319,4 +319,4 @@ packages: version: "0.1.0" sdks: dart: ">=2.9.0-14.0.dev <3.0.0" - flutter: ">=1.12.13+hotfix.5 <2.0.0" + flutter: ">=1.17.0 <2.0.0" diff --git a/pubspec.lock b/pubspec.lock index 958076bd..177d678f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -258,4 +258,4 @@ packages: version: "0.1.0" sdks: dart: ">=2.9.0-14.0.dev <3.0.0" - flutter: ">=1.12.13+hotfix.5 <2.0.0" + flutter: ">=1.17.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 5a00a5e7..54f4162c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,6 +5,7 @@ homepage: https://github.com/lohanidamodar/pdf_viewer environment: sdk: ">=2.1.0 <3.0.0" + flutter: ">=1.17.0 <2.0.0" dependencies: flutter: @@ -15,6 +16,9 @@ dependencies: flutter: plugin: - androidPackage: pt.tribeiro.flutter_plugin_pdf_viewer - pluginClass: FlutterPluginPdfViewerPlugin - + platforms: + android: + package: pt.tribeiro.flutter_plugin_pdf_viewer + pluginClass: FlutterPluginPdfViewerPlugin + ios: + pluginClass: FlutterPluginPdfViewerPlugin \ No newline at end of file