diff --git a/CHANGELOG.md b/CHANGELOG.md index 794725f0..4e07af2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.3.2 + +- upgrade android-pdf-viewer from 3.3.0-beta.1[https://github.com/93cgutierrez/AndroidPdfViewer/releases/tag/3.3.0-beta.1] This is a fork of the [AndroidPdfViewer](https://github.com/mhiew/AndroidPdfViewer) + ## 1.3.1 - Upgrade compileSdkVersion to 33 diff --git a/android/build.gradle b/android/build.gradle index d8490667..7cc374f7 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -5,6 +5,7 @@ buildscript { repositories { google() mavenCentral() + maven { url 'https://jitpack.io' } } dependencies { @@ -16,6 +17,7 @@ rootProject.allprojects { repositories { google() mavenCentral() + maven { url 'https://jitpack.io' } } } @@ -35,6 +37,9 @@ android { } dependencies { - implementation 'com.github.mhiew:android-pdf-viewer:3.2.0-beta.3' + implementation("com.github.93cgutierrez:AndroidPdfViewer:3.3.0-beta.3") + api("com.github.mhiew:pdfium-android:1.9.2") + //gson + implementation 'com.google.code.gson:gson:2.10.1' } diff --git a/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java b/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java index 7b91d027..77ea9d35 100644 --- a/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java +++ b/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java @@ -4,6 +4,8 @@ import android.view.View; import android.net.Uri; +import androidx.annotation.NonNull; + import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; @@ -22,11 +24,16 @@ import com.github.barteksc.pdfviewer.util.FitPolicy; import com.github.barteksc.pdfviewer.link.LinkHandler; +import com.google.gson.Gson; + +import org.json.JSONObject; public class FlutterPDFView implements PlatformView, MethodCallHandler { private final PDFView pdfView; private final MethodChannel methodChannel; private final LinkHandler linkHandler; + // Initialize Gson + Gson gson = new Gson(); @SuppressWarnings("unchecked") FlutterPDFView(Context context, BinaryMessenger messenger, int id, Map params) { @@ -40,16 +47,18 @@ public class FlutterPDFView implements PlatformView, MethodCallHandler { Configurator config = null; if (params.get("filePath") != null) { - String filePath = (String) params.get("filePath"); - config = pdfView.fromUri(getURI(filePath)); - } - else if (params.get("pdfData") != null) { - byte[] data = (byte[]) params.get("pdfData"); - config = pdfView.fromBytes(data); + String filePath = (String) params.get("filePath"); + config = pdfView.fromUri(getURI(filePath)); + } else if (params.get("pdfData") != null) { + byte[] data = (byte[]) params.get("pdfData"); + config = pdfView.fromBytes(data); } if (config != null) { config + .enableDoubletap(getBoolean(params, "enableDoubleTap")) + .enableAntialiasing(getBoolean(params, "enableAntialiasing")) + .enableAnnotationRendering(getBoolean(params, "enableAnnotationRendering")) .enableSwipe(getBoolean(params, "enableSwipe")) .swipeHorizontal(getBoolean(params, "swipeHorizontal")) .password(getString(params, "password")) @@ -58,41 +67,69 @@ else if (params.get("pdfData") != null) { .pageFling(getBoolean(params, "pageFling")) .pageSnap(getBoolean(params, "pageSnap")) .pageFitPolicy(getFitPolicy(params)) - .enableAnnotationRendering(true) - .linkHandler(linkHandler). - enableAntialiasing(false) + .linkHandler(linkHandler) // .fitEachPage(getBoolean(params,"fitEachPage")) - .onPageChange(new OnPageChangeListener() { - @Override - public void onPageChanged(int page, int total) { - Map args = new HashMap<>(); - args.put("page", page); - args.put("total", total); - methodChannel.invokeMethod("onPageChanged", args); - } - }).onError(new OnErrorListener() { - @Override - public void onError(Throwable t) { - Map args = new HashMap<>(); - args.put("error", t.toString()); - methodChannel.invokeMethod("onError", args); - } - }).onPageError(new OnPageErrorListener() { - @Override - public void onPageError(int page, Throwable t) { - Map args = new HashMap<>(); - args.put("page", page); - args.put("error", t.toString()); - methodChannel.invokeMethod("onPageError", args); - } - }).onRender(new OnRenderListener() { - @Override - public void onInitiallyRendered(int pages) { - Map args = new HashMap<>(); - args.put("pages", pages); - methodChannel.invokeMethod("onRender", args); - } - }).enableDoubletap(true).defaultPage(getInt(params, "defaultPage")).load(); + .onTap(motionEvent -> { + Map args = new HashMap<>(); + // Convert the object to JSON + String json = gson.toJson(motionEvent); + args.put("motionEvent", json); + methodChannel.invokeMethod("onTap", args); + return true; + }) + .onDoubleTap((animator, oldZoom, newZoom) -> { + Map args = new HashMap<>(); + // Convert the object to JSON + String json = gson.toJson(animator); + args.put("animator", json); + args.put("oldZoom", oldZoom); + args.put("newZoom", newZoom); + methodChannel.invokeMethod("onDoubleTap", args); + return true; + }) + .onPinchZoom((animator, oldZoom, newZoom) -> { + Map args = new HashMap<>(); + // Convert the object to JSON + String json = gson.toJson(animator); + args.put("animator", json); + args.put("oldZoom", oldZoom); + args.put("newZoom", newZoom); + methodChannel.invokeMethod("onPinchZoom", args); + return true; + }) + .onScrollAnimation((animation, scrollMoveDirection) -> { + Map args = new HashMap<>(); + // Convert the object to JSON + String json = gson.toJson(animation); + args.put("animation", json); + args.put("scrollMoveDirection", scrollMoveDirection); + methodChannel.invokeMethod("onScrollAnimation", args); + return true; + }) + .onPageChange((page, total) -> { + Map args = new HashMap<>(); + args.put("page", page); + args.put("total", total); + methodChannel.invokeMethod("onPageChanged", args); + }) + .onError(throwable -> { + Map args = new HashMap<>(); + args.put("error", throwable.toString()); + methodChannel.invokeMethod("onError", args); + }) + .onPageError((page, throwable) -> { + Map args = new HashMap<>(); + args.put("page", page); + args.put("error", throwable.toString()); + methodChannel.invokeMethod("onPageError", args); + }) + .onRender(pages -> { + Map args = new HashMap<>(); + args.put("pages", pages); + methodChannel.invokeMethod("onRender", args); + }) + .defaultPage(getInt(params, "defaultPage")) + .load(); } } @@ -101,8 +138,9 @@ public View getView() { return pdfView; } + //CAHNGE FLOAT IN AND OUT FOR DOUBLE @Override - public void onMethodCall(MethodCall methodCall, Result result) { + public void onMethodCall(MethodCall methodCall, @NonNull Result result) { switch (methodCall.method) { case "pageCount": getPageCount(result); @@ -113,6 +151,54 @@ public void onMethodCall(MethodCall methodCall, Result result) { case "setPage": setPage(methodCall, result); break; + + case "zoomTo": + zoomTo(methodCall, result); + break; + case "resetZoom": + resetZoom(result); + break; + case "getZoom": + getZoom(result); + break; + case "getPageSize": + getPageSize(methodCall, result); + break; + case "getPageWidth": + getPageWidth(methodCall, result); + break; + case "getPageHeight": + getPageHeight(methodCall, result); + break; + case "getSpacingPx": + getSpacingPx(result); + break; + case "getCurrentXOffset": + getCurrentXOffset(result); + break; + case "getCurrentYOffset": + getCurrentYOffset(result); + break; + case "getPageSpacing": + getPageSpacing(methodCall, result); + break; + case "getPageLength": + getPageLength(methodCall, result); + break; + case "getPageSpacingWithZoom": + getPageSpacingWithZoom(methodCall, result); + break; + case "getPageOffset": + getPageOffset(methodCall, result); + break; + case "getSecondaryPageOffset": + getSecondaryPageOffset(methodCall, result); + break; + case "getPageAtOffset": + getPageAtOffset(methodCall, result); + break; + + case "updateSettings": updateSettings(methodCall, result); break; @@ -122,6 +208,154 @@ public void onMethodCall(MethodCall methodCall, Result result) { } } + private void getPageAtOffset(MethodCall methodCall, Result result) { + if (methodCall.argument("offset") != null && methodCall.argument("zoom") != null) { + + Double offsetDouble = (Double) methodCall.argument("offset"); + float offsetFloat = 0; + if (offsetDouble != null) { + offsetFloat = offsetDouble.floatValue(); + } + + Double zoomDouble = (Double) methodCall.argument("zoom"); + float zoomFloat = PDFView.DEFAULT_MIN_SCALE; + if (zoomDouble != null) { + zoomFloat = zoomDouble.floatValue(); + } + + result.success(pdfView.getPageAtOffset(offsetFloat, zoomFloat)); + } + } + + private void getSecondaryPageOffset(MethodCall methodCall, Result result) { + if (methodCall.argument("pageIndex") != null && methodCall.argument("zoom") != null) { + int page = (int) methodCall.argument("pageIndex"); + Double zoomDouble = (Double) methodCall.argument("zoom"); + float zoomFloat = PDFView.DEFAULT_MIN_SCALE; + if (zoomDouble != null) { + zoomFloat = zoomDouble.floatValue(); + } + Float secondaryPageOffset = pdfView.getSecondaryPageOffset(page, zoomFloat); + + result.success(secondaryPageOffset == null ? null : secondaryPageOffset.doubleValue()); + } + } + + private void getPageOffset(MethodCall methodCall, Result result) { + if (methodCall.argument("pageIndex") != null && methodCall.argument("zoom") != null) { + int page = (int) methodCall.argument("pageIndex"); + Double zoomDouble = (Double) methodCall.argument("zoom"); + float zoomFloat = PDFView.DEFAULT_MIN_SCALE; + if (zoomDouble != null) { + zoomFloat = zoomDouble.floatValue(); + } + Float pageOffset = pdfView.getPageOffset(page, zoomFloat); + + result.success(pageOffset == null ? null : pageOffset.doubleValue()); + } + } + + private void getPageSpacingWithZoom(MethodCall methodCall, Result result) { + if (methodCall.argument("pageIndex") != null && methodCall.argument("zoom") != null) { + int page = (int) methodCall.argument("pageIndex"); + Double zoomDouble = (Double) methodCall.argument("zoom"); + float zoomFloat = PDFView.DEFAULT_MIN_SCALE; + if (zoomDouble != null) { + zoomFloat = zoomDouble.floatValue(); + } + Float pageSpacing = pdfView.getPageSpacing(page, zoomFloat); + + result.success(pageSpacing == null ? null : pdfView.getPageSpacing(page, zoomFloat).doubleValue()); + } + } + + private void getPageLength(MethodCall methodCall, Result result) { + if (methodCall.argument("pageIndex") != null && methodCall.argument("zoom") != null) { + int page = (int) methodCall.argument("pageIndex"); + Double zoomDouble = (Double) methodCall.argument("zoom"); + float zoomFloat = PDFView.DEFAULT_MIN_SCALE; + if (zoomDouble != null) { + zoomFloat = zoomDouble.floatValue(); + } + Float pageLength = pdfView.getPageLength(page, zoomFloat); + + result.success(pageLength == null ? null : pageLength.doubleValue()); + } + } + + private void getPageSpacing(MethodCall methodCall, Result result) { + if (methodCall.argument("pageIndex") != null) { + int page = (int) methodCall.argument("pageIndex"); + Float pageSpacing = pdfView.getPageSpacing(page); + + result.success(pageSpacing == null ? null : pageSpacing.doubleValue()); + } + } + + private void getCurrentYOffset(Result result) { + double currentYOffsetDouble = pdfView.getCurrentYOffset(); + result.success(currentYOffsetDouble); + } + + private void getCurrentXOffset(Result result) { + double currentXOffsetDouble = pdfView.getCurrentXOffset(); + result.success(currentXOffsetDouble); + } + + private void getSpacingPx(Result result) { + result.success(pdfView.getSpacingPx()); + } + + private void getPageHeight(MethodCall methodCall, Result result) { + if (methodCall.argument("pageIndex") != null) { + int page = (int) methodCall.argument("pageIndex"); + double heightDouble = pdfView.getPageSize(page).getHeight(); + result.success(heightDouble); + } + } + + private void getPageWidth(MethodCall methodCall, Result result) { + if (methodCall.argument("pageIndex") != null) { + int page = (int) methodCall.argument("pageIndex"); + double widthDouble = pdfView.getPageSize(page).getWidth(); + result.success(widthDouble); + } + } + + private void getPageSize(MethodCall methodCall, Result result) { + String json = gson.toJson(pdfView.getPageSize(pdfView.getCurrentPage())); + if (methodCall.argument("pageIndex") != null) { + int page = (int) methodCall.argument("pageIndex"); + //convert Object to JSON + json = gson.toJson(pdfView.getPageSize(page)); + } + result.success(json); + } + + private void getZoom(Result result) { + double zoomDouble = pdfView.getZoom(); + result.success(pdfView.getZoom()); + } + + private void resetZoom(Result result) { + pdfView.resetZoom(); + result.success(true); + } + + + private void zoomTo(MethodCall methodCall, Result result) { + if (methodCall.argument("zoom") != null) { + Double zoomDouble = (Double) methodCall.argument("zoom"); + float zoomFloat = PDFView.DEFAULT_MIN_SCALE; + if (zoomDouble != null) { + zoomFloat = zoomDouble.floatValue(); + } + pdfView.zoomTo(zoomFloat); + } + + result.success(true); + } + void getPageCount(Result result) { result.success(pdfView.getPageCount()); } @@ -148,6 +382,16 @@ private void updateSettings(MethodCall methodCall, Result result) { private void applySettings(Map settings) { for (String key : settings.keySet()) { switch (key) { + case "enableDoubleTap": + //TODO: SHOULD CHECK + //pdfView.enableDoubletap(getBoolean(settings, key)); + break; + case "enableAntialiasing": + pdfView.enableAntialiasing(getBoolean(settings, key)); + break; + case "enableAnnotationRendering": + pdfView.enableAnnotationRendering(getBoolean(settings, key)); + break; case "enableSwipe": pdfView.setSwipeEnabled(getBoolean(settings, key)); break; diff --git a/example/android/build.gradle b/example/android/build.gradle index 82083a81..3c18002c 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -24,11 +24,11 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } configurations.all { resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' } -} \ No newline at end of file +} diff --git a/example/pubspec.lock b/example/pubspec.lock index a1942a8f..acd5f183 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,10 +5,10 @@ packages: dependency: transitive description: name: async - sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" url: "https://pub.dev" source: hosted - version: "2.10.0" + version: "2.11.0" boolean_selector: dependency: transitive description: @@ -21,10 +21,10 @@ packages: dependency: transitive description: name: characters - sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.3.0" clock: dependency: transitive description: @@ -37,10 +37,10 @@ packages: dependency: transitive description: name: collection - sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" url: "https://pub.dev" source: hosted - version: "1.17.0" + version: "1.17.1" cupertino_icons: dependency: "direct main" description: @@ -84,7 +84,7 @@ packages: path: ".." relative: true source: path - version: "1.3.0" + version: "1.3.2" flutter_test: dependency: "direct dev" description: flutter @@ -94,18 +94,18 @@ packages: dependency: transitive description: name: js - sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 url: "https://pub.dev" source: hosted - version: "0.6.5" + version: "0.6.7" matcher: dependency: transitive description: name: matcher - sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" + sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" url: "https://pub.dev" source: hosted - version: "0.12.13" + version: "0.12.15" material_color_utilities: dependency: transitive description: @@ -118,18 +118,18 @@ packages: dependency: transitive description: name: meta - sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.9.1" path: dependency: transitive description: name: path - sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.8.3" path_provider: dependency: "direct main" description: @@ -251,10 +251,10 @@ packages: dependency: transitive description: name: test_api - sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 + sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb url: "https://pub.dev" source: hosted - version: "0.4.16" + version: "0.5.1" vector_math: dependency: transitive description: @@ -280,5 +280,5 @@ packages: source: hosted version: "1.0.0" sdks: - dart: ">=2.18.0 <4.0.0" + dart: ">=3.0.0-0 <4.0.0" flutter: ">=3.0.0" diff --git a/lib/flutter_pdfview.dart b/lib/flutter_pdfview.dart index c18346c3..9fca30c4 100644 --- a/lib/flutter_pdfview.dart +++ b/lib/flutter_pdfview.dart @@ -12,6 +12,13 @@ typedef PageChangedCallback = void Function(int? page, int? total); typedef ErrorCallback = void Function(dynamic error); typedef PageErrorCallback = void Function(int? page, dynamic error); typedef LinkHandlerCallback = void Function(String? uri); +typedef OnTapCallback = void Function(String? motionEvent); +typedef OnDoubleTapCallback = void Function( + String? animation, double oldZoom, double newZoom); +typedef OnPinchZoomCallback = void Function( + String? animation, double oldZoom, double newZoom); +typedef OnScrollAnimationCallback = void Function( + String? animation, int scrollMoveDirection); enum FitPolicy { WIDTH, HEIGHT, BOTH } @@ -26,6 +33,13 @@ class PDFView extends StatefulWidget { this.onError, this.onPageError, this.onLinkHandler, + this.enableDoubleTap = true, + this.onTap, + this.onDoubleTap, + this.onPinchZoom, + this.onScrollAnimation, + this.enableAntialiasing = true, + this.enabledAnnotationRendering = false, this.gestureRecognizers, this.enableSwipe = true, this.swipeHorizontal = false, @@ -59,6 +73,24 @@ class PDFView extends StatefulWidget { /// Invokes on page cannot be rendered or something happens final PageErrorCallback? onPageError; + /// Invokes on tap onPDFView + final OnTapCallback? onTap; + + /// Invokes on double tap onPDFView + final OnDoubleTapCallback? onDoubleTap; + + /// Invokes on pinch zoom onPDFView + final OnPinchZoomCallback? onPinchZoom; + + /// Return animation and scroll direction + final OnScrollAnimationCallback? onScrollAnimation; + + /// Enable antialiasing. Default true + final bool enableAntialiasing; + + /// Enable annotation rendering. Default false + final bool enabledAnnotationRendering; + /// Used with preventLinkNavigation=true. It's helpful to customize link navigation final LinkHandlerCallback? onLinkHandler; @@ -82,6 +114,9 @@ class PDFView extends StatefulWidget { /// Indicates whether or not the user can swipe to change pages in the PDF document. If set to true, swiping is enabled. final bool enableSwipe; + /// Indicates whether or not the user can double tap to zoom in the PDF document. If set to true, double tap is enabled. + final bool enableDoubleTap; + /// Indicates whether or not the user can swipe horizontally to change pages in the PDF document. If set to true, horizontal swiping is enabled. final bool swipeHorizontal; @@ -215,7 +250,10 @@ class _CreationParams { class _PDFViewSettings { _PDFViewSettings( - {this.enableSwipe, + {this.enableDoubleTap, + this.enableAntialiasing, + this.enabledAnnotationRendering, + this.enableSwipe, this.swipeHorizontal, this.password, this.nightMode, @@ -229,6 +267,9 @@ class _PDFViewSettings { static _PDFViewSettings fromWidget(PDFView widget) { return _PDFViewSettings( + enableDoubleTap: widget.enableDoubleTap, + enableAntialiasing: widget.enableAntialiasing, + enabledAnnotationRendering: widget.enabledAnnotationRendering, enableSwipe: widget.enableSwipe, swipeHorizontal: widget.swipeHorizontal, password: widget.password, @@ -241,6 +282,9 @@ class _PDFViewSettings { preventLinkNavigation: widget.preventLinkNavigation); } + final bool? enableDoubleTap; + final bool? enableAntialiasing; + final bool? enabledAnnotationRendering; final bool? enableSwipe; final bool? swipeHorizontal; final String? password; @@ -250,11 +294,15 @@ class _PDFViewSettings { final bool? pageSnap; final int? defaultPage; final FitPolicy? fitPolicy; + // final bool? fitEachPage; final bool? preventLinkNavigation; Map toMap() { return { + 'enableDoubleTap': enableDoubleTap, + 'enableAntialiasing': enableAntialiasing, + 'enabledAnnotationRendering': enabledAnnotationRendering, 'enableSwipe': enableSwipe, 'swipeHorizontal': swipeHorizontal, 'password': password, @@ -271,6 +319,16 @@ class _PDFViewSettings { Map updatesMap(_PDFViewSettings newSettings) { final Map updates = {}; + if (enableDoubleTap != newSettings.enableDoubleTap) { + updates['enableDoubleTap'] = newSettings.enableDoubleTap; + } + if (enableAntialiasing != newSettings.enableAntialiasing) { + updates['enableAntialiasing'] = newSettings.enableAntialiasing; + } + if (enabledAnnotationRendering != newSettings.enabledAnnotationRendering) { + updates['enabledAnnotationRendering'] = + newSettings.enabledAnnotationRendering; + } if (enableSwipe != newSettings.enableSwipe) { updates['enableSwipe'] = newSettings.enableSwipe; } @@ -334,6 +392,37 @@ class PDFViewController { _widget.onLinkHandler!(call.arguments); } + return null; + + case 'onTap': + if (_widget.onTap != null) { + _widget.onTap!(call.arguments['motionEvent']); + } + + return null; + + case 'onDoubleTap': + if (_widget.onDoubleTap != null) { + _widget.onDoubleTap!(call.arguments['animation'], + call.arguments['oldZoom'], call.arguments['newZoom']); + } + + return null; + + case 'onPinchZoom': + if (_widget.onPinchZoom != null) { + _widget.onPinchZoom!(call.arguments['animation'], + call.arguments['oldZoom'], call.arguments['newZoom']); + } + + return null; + + case 'onScrollAnimation': + if (_widget.onScrollAnimation != null) { + _widget.onScrollAnimation!(call.arguments['animation'], + call.arguments['scrollMoveDirection']); + } + return null; } throw MissingPluginException( @@ -358,6 +447,162 @@ class PDFViewController { return isSet; } + Future zoomTo(double zoom) async { + final bool? isSet = await _channel.invokeMethod('zoomTo', { + 'zoom': zoom, + }); + return isSet; + } + + Future resetZoom() async { + final bool? isSet = await _channel.invokeMethod('resetZoom'); + return isSet; + } + + //get zoom + Future getZoom() async { + final double? zoom = await _channel.invokeMethod('getZoom'); + return zoom; + } + + //TODO: OBJECT //private final float width; + // private final float height; + //SizeF getPageSize(int pageIndex) + Future?> getPageSize(int pageIndex) async { + //TODO: PROOF JSON + final Map? pageSize = + await _channel.invokeMethod('getPageSize', { + 'pageIndex': pageIndex, + }); + return pageSize; + } + + //get width page index + Future getPageWidth(int pageIndex) async { + final double? width = + await _channel.invokeMethod('getPageWidth', { + 'pageIndex': pageIndex, + }); + return width; + } + + //get height page index + Future getPageHeight(int pageIndex) async { + final double? height = + await _channel.invokeMethod('getPageHeight', { + 'pageIndex': pageIndex, + }); + return height; + } + + //get spacing between pages, in pixels + Future getSpacingPx() async { + final int? spacing = await _channel.invokeMethod('getSpacingPx'); + return spacing; + } + + // getCurrentXOffset + Future getCurrentXOffset() async { + final double? currentXOffset = + await _channel.invokeMethod('getCurrentXOffset'); + return currentXOffset; + } + + // getCurrentYOffset + Future getCurrentYOffset() async { + final double? currentYOffset = + await _channel.invokeMethod('getCurrentYOffset'); + return currentYOffset; + } + + /// Get spacing between pages, in pixels without zooming. + /// + /// @param pageIndex (int) the index of the page + /// @return (Float) spacing above and below the view in pixels + /// return null if not found. + Future getPageSpacing(int pageIndex) async { + final double? spacing = + await _channel.invokeMethod('getPageSpacing', { + 'pageIndex': pageIndex, + }); + return spacing; + } + + /// Get the page's height if swiping vertical, or width if swiping horizontal. + /// + /// @param pageIndex (int) the page index + /// @param zoom (float) the current zoom + /// @return (Float) the page's height (if swiping vertical) or width (if swiping horizontal) + /// return null if not found. + Future getPageLength(int pageIndex, double zoom) async { + final double? length = + await _channel.invokeMethod('getPageLength', { + 'pageIndex': pageIndex, + 'zoom': zoom, + }); + return length; + } + + /// Get spacing between pages with current zoom, in pixels. + /// + /// @param pageIndex (int) the page index + /// @param zoom (float) the current zoom + /// @return (Float) spacing above and below the view in pixels + /// return null if not found. + Future getPageSpacingWithZoom(int pageIndex, double zoom) async { + final double? spacing = + await _channel.invokeMethod('getPageSpacingWithZoom', { + 'pageIndex': pageIndex, + 'zoom': zoom, + }); + return spacing; + } + + /// Get primary page offset, that is Y for vertical scroll and X for horizontal scroll. + /// + /// @param pageIndex (int) the page index + /// @param zoom (float) the current zoom + /// @return (Float) offset of the page + /// return null if not found. + Future getPageOffset(int pageIndex, double zoom) async { + final double? offset = + await _channel.invokeMethod('getPageOffset', { + 'pageIndex': pageIndex, + 'zoom': zoom, + }); + return offset; + } + + /// Get secondary page offset, that is X for vertical scroll and Y for horizontal scroll. + /// + /// @param pageIndex (int) the page index + /// @param zoom (float) the current zoom + /// @return (Float) offset of the page + /// return null if not found. + Future getSecondaryPageOffset(int pageIndex, double zoom) async { + final double? offset = + await _channel.invokeMethod('getSecondaryPageOffset', { + 'pageIndex': pageIndex, + 'zoom': zoom, + }); + return offset; + } + + /// Get current page offset. + /// + /// @param offset (float) the page offset + /// @param zoom (float) the current zoom + /// @return (Integer) the page index. + /// return null if not found. + Future getPageAtOffset(double offset, double zoom) async { + final int? page = + await _channel.invokeMethod('getPageAtOffset', { + 'offset': offset, + 'zoom': zoom, + }); + return page; + } + Future _updateWidget(PDFView widget) async { _widget = widget; await _updateSettings(_PDFViewSettings.fromWidget(widget)); diff --git a/pubspec.yaml b/pubspec.yaml index f80275c4..edb10329 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: flutter_pdfview -description: A Flutter plugin that provides a PDFView widget on Android and iOS. -version: 1.3.1 -homepage: https://github.com/endigo/flutter_pdfview +description: A Fork to [https://github.com/endigo/flutter_pdfview] Flutter plugin that provides a PDFView widget on Android and iOS. +version: 1.3.2 +homepage: https://github.com/93cgutierrez/flutter_pdfview environment: sdk: ">=2.17.0 <4.0.0"