From ff0e235ebfd1e1ff2984c16dd0fb5cbac7b97b01 Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez <93cgutierrez@gmail.com> Date: Thu, 31 Aug 2023 16:26:14 -0500 Subject: [PATCH 1/8] #v1.3.2 20230831 Generation version 1.3.2 new feature: 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) --- CHANGELOG.md | 4 ++++ android/build.gradle | 3 ++- example/pubspec.lock | 36 ++++++++++++++++++------------------ pubspec.yaml | 6 +++--- 4 files changed, 27 insertions(+), 22 deletions(-) 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..96f03255 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -35,6 +35,7 @@ android { } dependencies { - implementation 'com.github.mhiew:android-pdf-viewer:3.2.0-beta.3' + implementation("com.github.93cgutierrez:AndroidPdfViewer:3.3.0-beta.1") + api("com.github.mhiew:pdfium-android:1.9.2") } 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/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" From 7241a1b09055d89c96a38fe7902d54c6a8870259 Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez <93cgutierrez@gmail.com> Date: Thu, 31 Aug 2023 16:48:17 -0500 Subject: [PATCH 2/8] fix repository url --- android/build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/build.gradle b/android/build.gradle index 96f03255..87dee355 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' } } } From 9307aaa588ac75a409306d4682f9a93e8cc01dae Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez <93cgutierrez@gmail.com> Date: Thu, 31 Aug 2023 19:53:52 -0500 Subject: [PATCH 3/8] #feature/add_methods_android CG 20230831 add methods android pdf viewer --- android/build.gradle | 2 + .../pdfviewflutter/FlutterPDFView.java | 170 +++++++--- lib/flutter_pdfview.dart | 297 ++++++++++++++++-- 3 files changed, 403 insertions(+), 66 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 87dee355..f4992c72 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -39,5 +39,7 @@ android { dependencies { implementation("com.github.93cgutierrez:AndroidPdfViewer:3.3.0-beta.1") 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..a8271cb8 100644 --- a/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java +++ b/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java @@ -22,11 +22,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 +45,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 +65,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(); } } @@ -113,6 +148,25 @@ 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); + + //TODO: CREATE METHOD ... AQUI VAMOS + + case "updateSettings": updateSettings(methodCall, result); break; @@ -122,6 +176,42 @@ public void onMethodCall(MethodCall methodCall, Result result) { } } + private void getPageWidth(MethodCall methodCall, Result result) { + if (methodCall.argument("pageIndex") != null) { + int page = (int) methodCall.argument("pageIndex"); + result.success(pdfView.getPageSize(page).getWidth()); + } + } + + 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) { + 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) { + float zoom = (float) methodCall.argument("zoom"); + pdfView.zoomTo(zoom); + } + + result.success(true); + } + void getPageCount(Result result) { result.success(pdfView.getPageCount()); } diff --git a/lib/flutter_pdfview.dart b/lib/flutter_pdfview.dart index c18346c3..34b45a3c 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( + Animation animation, double oldZoom, double newZoom); +typedef OnPinchZoomCallback = void Function( + Animation animation, double oldZoom, double newZoom); +typedef OnScrollAnimationCallback = void Function( + Animation 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, @@ -38,7 +52,8 @@ class PDFView extends StatefulWidget { this.defaultPage = 0, this.fitPolicy = FitPolicy.WIDTH, this.preventLinkNavigation = false, - }) : assert(filePath != null || pdfData != null), + }) + : assert(filePath != null || pdfData != null), super(key: key); @override @@ -59,6 +74,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 +115,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; @@ -119,17 +155,15 @@ class PDFView extends StatefulWidget { class _PDFViewState extends State { final Completer _controller = - Completer(); + Completer(); @override Widget build(BuildContext context) { if (defaultTargetPlatform == TargetPlatform.android) { return PlatformViewLink( viewType: 'plugins.endigo.io/pdfview', - surfaceFactory: ( - BuildContext context, - PlatformViewController controller, - ) { + surfaceFactory: (BuildContext context, + PlatformViewController controller,) { return AndroidViewSurface( controller: controller as AndroidViewController, gestureRecognizers: widget.gestureRecognizers ?? @@ -145,8 +179,9 @@ class _PDFViewState extends State { creationParams: _CreationParams.fromWidget(widget).toMap(), creationParamsCodec: const StandardMessageCodec(), ) - ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated) - ..addOnPlatformViewCreatedListener((int id) { + ..addOnPlatformViewCreatedListener(params + .onPlatformViewCreated)..addOnPlatformViewCreatedListener(( + int id) { _onPlatformViewCreated(id); }) ..create(); @@ -177,7 +212,7 @@ class _PDFViewState extends State { void didUpdateWidget(PDFView oldWidget) { super.didUpdateWidget(oldWidget); _controller.future.then( - (PDFViewController controller) => controller._updateWidget(widget)); + (PDFViewController controller) => controller._updateWidget(widget)); } } @@ -214,21 +249,26 @@ class _CreationParams { } class _PDFViewSettings { - _PDFViewSettings( - {this.enableSwipe, - this.swipeHorizontal, - this.password, - this.nightMode, - this.autoSpacing, - this.pageFling, - this.pageSnap, - this.defaultPage, - this.fitPolicy, - // this.fitEachPage, - this.preventLinkNavigation}); + _PDFViewSettings({this.enableDoubleTap, + this.enableAntialiasing, + this.enabledAnnotationRendering, + this.enableSwipe, + this.swipeHorizontal, + this.password, + this.nightMode, + this.autoSpacing, + this.pageFling, + this.pageSnap, + this.defaultPage, + this.fitPolicy, + // this.fitEachPage, + this.preventLinkNavigation}); 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 +281,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 +293,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 +318,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; } @@ -288,10 +345,9 @@ class _PDFViewSettings { } class PDFViewController { - PDFViewController._( - int id, - this._widget, - ) : _channel = MethodChannel('plugins.endigo.io/pdfview_$id') { + PDFViewController._(int id, + this._widget,) + : _channel = MethodChannel('plugins.endigo.io/pdfview_$id') { _settings = _PDFViewSettings.fromWidget(_widget); _channel.setMethodCallHandler(_onMethodCall); } @@ -334,6 +390,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( @@ -352,12 +439,170 @@ class PDFViewController { Future setPage(int page) async { final bool? isSet = - await _channel.invokeMethod('setPage', { + await _channel.invokeMethod('setPage', { 'page': page, }); 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; + } + + //TODO: CREATE METHOD ... AQUI VAMOS + //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 double? 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)); From 0fb218c0c1e7f14aeafd83c4fa38b7020139eb31 Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez <93cgutierrez@gmail.com> Date: Thu, 7 Sep 2023 10:53:45 -0500 Subject: [PATCH 4/8] AndroidPdfViewer:3.3.0-beta.3 --- android/build.gradle | 2 +- .../pdfviewflutter/FlutterPDFView.java | 111 +++++++++++++++++- example/android/build.gradle | 4 +- lib/flutter_pdfview.dart | 2 - 4 files changed, 111 insertions(+), 8 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index f4992c72..7cc374f7 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -37,7 +37,7 @@ android { } dependencies { - implementation("com.github.93cgutierrez:AndroidPdfViewer:3.3.0-beta.1") + 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 a8271cb8..4c8f26ab 100644 --- a/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java +++ b/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java @@ -148,6 +148,7 @@ public void onMethodCall(MethodCall methodCall, Result result) { case "setPage": setPage(methodCall, result); break; + case "zoomTo": zoomTo(methodCall, result); break; @@ -160,11 +161,39 @@ public void onMethodCall(MethodCall methodCall, Result result) { case "getPageSize": getPageSize(methodCall, result); break; - case "getPageWidth": getPageWidth(methodCall, result); - - //TODO: CREATE METHOD ... AQUI VAMOS + 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": @@ -176,6 +205,72 @@ public void onMethodCall(MethodCall methodCall, Result result) { } } + private void getPageAtOffset(MethodCall methodCall, Result result) { + if (methodCall.argument("offset") != null && methodCall.argument("zoom") != null) { + float offset = (float) methodCall.argument("offset"); + float zoom = (float) methodCall.argument("zoom"); + result.success(pdfView.getPageAtOffset(offset, zoom)); + } + } + + private void getSecondaryPageOffset(MethodCall methodCall, Result result) { + if (methodCall.argument("pageIndex") != null && methodCall.argument("zoom") != null) { + int page = (int) methodCall.argument("pageIndex"); + float zoom = (float) methodCall.argument("zoom"); + result.success(pdfView.getSecondaryPageOffset(page, zoom)); + } + } + + private void getPageOffset(MethodCall methodCall, Result result) { + if (methodCall.argument("pageIndex") != null && methodCall.argument("zoom") != null) { + int page = (int) methodCall.argument("pageIndex"); + float zoom = (float) methodCall.argument("zoom"); + result.success(pdfView.getPageOffset(page, zoom)); + } + } + + private void getPageSpacingWithZoom(MethodCall methodCall, Result result) { + if (methodCall.argument("pageIndex") != null && methodCall.argument("zoom") != null) { + int page = (int) methodCall.argument("pageIndex"); + float zoom = (float) methodCall.argument("zoom"); + result.success(pdfView.getPageSpacing(page, zoom)); + } + } + + private void getPageLength(MethodCall methodCall, Result result) { + if (methodCall.argument("pageIndex") != null && methodCall.argument("zoom") != null) { + int page = (int) methodCall.argument("pageIndex"); + float zoom = (float) methodCall.argument("zoom"); + result.success(pdfView.getPageLength(page, zoom)); + } + } + + private void getPageSpacing(MethodCall methodCall, Result result) { + if (methodCall.argument("pageIndex") != null) { + int page = (int) methodCall.argument("pageIndex"); + result.success(pdfView.getPageSpacing(page)); + } + } + + private void getCurrentYOffset(Result result) { + result.success(pdfView.getCurrentYOffset()); + } + + private void getCurrentXOffset(Result result) { + result.success(pdfView.getCurrentXOffset()); + } + + 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"); + result.success(pdfView.getPageSize(page).getHeight()); + } + } + private void getPageWidth(MethodCall methodCall, Result result) { if (methodCall.argument("pageIndex") != null) { int page = (int) methodCall.argument("pageIndex"); @@ -238,6 +333,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/lib/flutter_pdfview.dart b/lib/flutter_pdfview.dart index 34b45a3c..8d8f7d36 100644 --- a/lib/flutter_pdfview.dart +++ b/lib/flutter_pdfview.dart @@ -475,7 +475,6 @@ class PDFViewController { return pageSize; } - //get width page index Future getPageWidth(int pageIndex) async { final double? width = @@ -485,7 +484,6 @@ class PDFViewController { return width; } - //TODO: CREATE METHOD ... AQUI VAMOS //get height page index Future getPageHeight(int pageIndex) async { final double? height = From d30b5c3abb65865c0a846adbd51a03127a72a891 Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez <93cgutierrez@gmail.com> Date: Thu, 7 Sep 2023 21:54:11 -0500 Subject: [PATCH 5/8] AndroidPdfViewer:3.3.0-beta.3 change variable types --- lib/flutter_pdfview.dart | 84 ++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/lib/flutter_pdfview.dart b/lib/flutter_pdfview.dart index 8d8f7d36..b3668b14 100644 --- a/lib/flutter_pdfview.dart +++ b/lib/flutter_pdfview.dart @@ -14,11 +14,11 @@ typedef PageErrorCallback = void Function(int? page, dynamic error); typedef LinkHandlerCallback = void Function(String? uri); typedef OnTapCallback = void Function(String? motionEvent); typedef OnDoubleTapCallback = void Function( - Animation animation, double oldZoom, double newZoom); + String? animation, double oldZoom, double newZoom); typedef OnPinchZoomCallback = void Function( - Animation animation, double oldZoom, double newZoom); + String? animation, double oldZoom, double newZoom); typedef OnScrollAnimationCallback = void Function( - Animation animation, int scrollMoveDirection); + String? animation, int scrollMoveDirection); enum FitPolicy { WIDTH, HEIGHT, BOTH } @@ -52,8 +52,7 @@ class PDFView extends StatefulWidget { this.defaultPage = 0, this.fitPolicy = FitPolicy.WIDTH, this.preventLinkNavigation = false, - }) - : assert(filePath != null || pdfData != null), + }) : assert(filePath != null || pdfData != null), super(key: key); @override @@ -155,15 +154,17 @@ class PDFView extends StatefulWidget { class _PDFViewState extends State { final Completer _controller = - Completer(); + Completer(); @override Widget build(BuildContext context) { if (defaultTargetPlatform == TargetPlatform.android) { return PlatformViewLink( viewType: 'plugins.endigo.io/pdfview', - surfaceFactory: (BuildContext context, - PlatformViewController controller,) { + surfaceFactory: ( + BuildContext context, + PlatformViewController controller, + ) { return AndroidViewSurface( controller: controller as AndroidViewController, gestureRecognizers: widget.gestureRecognizers ?? @@ -179,9 +180,8 @@ class _PDFViewState extends State { creationParams: _CreationParams.fromWidget(widget).toMap(), creationParamsCodec: const StandardMessageCodec(), ) - ..addOnPlatformViewCreatedListener(params - .onPlatformViewCreated)..addOnPlatformViewCreatedListener(( - int id) { + ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated) + ..addOnPlatformViewCreatedListener((int id) { _onPlatformViewCreated(id); }) ..create(); @@ -212,7 +212,7 @@ class _PDFViewState extends State { void didUpdateWidget(PDFView oldWidget) { super.didUpdateWidget(oldWidget); _controller.future.then( - (PDFViewController controller) => controller._updateWidget(widget)); + (PDFViewController controller) => controller._updateWidget(widget)); } } @@ -249,20 +249,21 @@ class _CreationParams { } class _PDFViewSettings { - _PDFViewSettings({this.enableDoubleTap, - this.enableAntialiasing, - this.enabledAnnotationRendering, - this.enableSwipe, - this.swipeHorizontal, - this.password, - this.nightMode, - this.autoSpacing, - this.pageFling, - this.pageSnap, - this.defaultPage, - this.fitPolicy, - // this.fitEachPage, - this.preventLinkNavigation}); + _PDFViewSettings( + {this.enableDoubleTap, + this.enableAntialiasing, + this.enabledAnnotationRendering, + this.enableSwipe, + this.swipeHorizontal, + this.password, + this.nightMode, + this.autoSpacing, + this.pageFling, + this.pageSnap, + this.defaultPage, + this.fitPolicy, + // this.fitEachPage, + this.preventLinkNavigation}); static _PDFViewSettings fromWidget(PDFView widget) { return _PDFViewSettings( @@ -345,9 +346,10 @@ class _PDFViewSettings { } class PDFViewController { - PDFViewController._(int id, - this._widget,) - : _channel = MethodChannel('plugins.endigo.io/pdfview_$id') { + PDFViewController._( + int id, + this._widget, + ) : _channel = MethodChannel('plugins.endigo.io/pdfview_$id') { _settings = _PDFViewSettings.fromWidget(_widget); _channel.setMethodCallHandler(_onMethodCall); } @@ -439,7 +441,7 @@ class PDFViewController { Future setPage(int page) async { final bool? isSet = - await _channel.invokeMethod('setPage', { + await _channel.invokeMethod('setPage', { 'page': page, }); return isSet; @@ -469,7 +471,7 @@ class PDFViewController { Future?> getPageSize(int pageIndex) async { //TODO: PROOF JSON final Map? pageSize = - await _channel.invokeMethod('getPageSize', { + await _channel.invokeMethod('getPageSize', { 'pageIndex': pageIndex, }); return pageSize; @@ -478,7 +480,7 @@ class PDFViewController { //get width page index Future getPageWidth(int pageIndex) async { final double? width = - await _channel.invokeMethod('getPageWidth', { + await _channel.invokeMethod('getPageWidth', { 'pageIndex': pageIndex, }); return width; @@ -487,7 +489,7 @@ class PDFViewController { //get height page index Future getPageHeight(int pageIndex) async { final double? height = - await _channel.invokeMethod('getPageHeight', { + await _channel.invokeMethod('getPageHeight', { 'pageIndex': pageIndex, }); return height; @@ -502,14 +504,14 @@ class PDFViewController { // getCurrentXOffset Future getCurrentXOffset() async { final double? currentXOffset = - await _channel.invokeMethod('getCurrentXOffset'); + await _channel.invokeMethod('getCurrentXOffset'); return currentXOffset; } // getCurrentYOffset Future getCurrentYOffset() async { final double? currentYOffset = - await _channel.invokeMethod('getCurrentYOffset'); + await _channel.invokeMethod('getCurrentYOffset'); return currentYOffset; } @@ -520,7 +522,7 @@ class PDFViewController { /// return null if not found. Future getPageSpacing(int pageIndex) async { final double? spacing = - await _channel.invokeMethod('getPageSpacing', { + await _channel.invokeMethod('getPageSpacing', { 'pageIndex': pageIndex, }); return spacing; @@ -534,7 +536,7 @@ class PDFViewController { /// return null if not found. Future getPageLength(int pageIndex, double zoom) async { final double? length = - await _channel.invokeMethod('getPageLength', { + await _channel.invokeMethod('getPageLength', { 'pageIndex': pageIndex, 'zoom': zoom, }); @@ -549,7 +551,7 @@ class PDFViewController { /// return null if not found. Future getPageSpacingWithZoom(int pageIndex, double zoom) async { final double? spacing = - await _channel.invokeMethod('getPageSpacingWithZoom', { + await _channel.invokeMethod('getPageSpacingWithZoom', { 'pageIndex': pageIndex, 'zoom': zoom, }); @@ -564,7 +566,7 @@ class PDFViewController { /// return null if not found. Future getPageOffset(int pageIndex, double zoom) async { final double? offset = - await _channel.invokeMethod('getPageOffset', { + await _channel.invokeMethod('getPageOffset', { 'pageIndex': pageIndex, 'zoom': zoom, }); @@ -579,7 +581,7 @@ class PDFViewController { /// return null if not found. Future getSecondaryPageOffset(int pageIndex, double zoom) async { final double? offset = - await _channel.invokeMethod('getSecondaryPageOffset', { + await _channel.invokeMethod('getSecondaryPageOffset', { 'pageIndex': pageIndex, 'zoom': zoom, }); @@ -594,7 +596,7 @@ class PDFViewController { /// return null if not found. Future getPageAtOffset(double offset, double zoom) async { final int? page = - await _channel.invokeMethod('getPageAtOffset', { + await _channel.invokeMethod('getPageAtOffset', { 'offset': offset, 'zoom': zoom, }); From 8dccd5e78645ff0987f07597fec8f24e818feea4 Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez <93cgutierrez@gmail.com> Date: Fri, 8 Sep 2023 09:12:04 -0500 Subject: [PATCH 6/8] #fixbug/fix_change_data_types CG 20230908 fix bug change data types android <=> dart --- .../pdfviewflutter/FlutterPDFView.java | 79 ++++++++++++++----- 1 file changed, 60 insertions(+), 19 deletions(-) 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 4c8f26ab..2c0644ef 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; @@ -136,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); @@ -207,57 +210,88 @@ public void onMethodCall(MethodCall methodCall, Result result) { private void getPageAtOffset(MethodCall methodCall, Result result) { if (methodCall.argument("offset") != null && methodCall.argument("zoom") != null) { - float offset = (float) methodCall.argument("offset"); - float zoom = (float) methodCall.argument("zoom"); - result.success(pdfView.getPageAtOffset(offset, zoom)); + + 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"); - float zoom = (float) methodCall.argument("zoom"); - result.success(pdfView.getSecondaryPageOffset(page, zoom)); + Double zoomDouble = (Double) methodCall.argument("zoom"); + float zoomFloat = PDFView.DEFAULT_MIN_SCALE; + if (zoomDouble != null) { + zoomFloat = zoomDouble.floatValue(); + } + result.success(pdfView.getSecondaryPageOffset(page, zoomFloat).doubleValue()); } } private void getPageOffset(MethodCall methodCall, Result result) { if (methodCall.argument("pageIndex") != null && methodCall.argument("zoom") != null) { int page = (int) methodCall.argument("pageIndex"); - float zoom = (float) methodCall.argument("zoom"); - result.success(pdfView.getPageOffset(page, zoom)); + Double zoomDouble = (Double) methodCall.argument("zoom"); + float zoomFloat = PDFView.DEFAULT_MIN_SCALE; + if (zoomDouble != null) { + zoomFloat = zoomDouble.floatValue(); + } + + result.success(pdfView.getPageOffset(page, zoomFloat).doubleValue()); } } private void getPageSpacingWithZoom(MethodCall methodCall, Result result) { if (methodCall.argument("pageIndex") != null && methodCall.argument("zoom") != null) { int page = (int) methodCall.argument("pageIndex"); - float zoom = (float) methodCall.argument("zoom"); - result.success(pdfView.getPageSpacing(page, zoom)); + Double zoomDouble = (Double) methodCall.argument("zoom"); + float zoomFloat = PDFView.DEFAULT_MIN_SCALE; + if (zoomDouble != null) { + zoomFloat = zoomDouble.floatValue(); + } + + result.success(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"); - float zoom = (float) methodCall.argument("zoom"); - result.success(pdfView.getPageLength(page, zoom)); + Double zoomDouble = (Double) methodCall.argument("zoom"); + float zoomFloat = PDFView.DEFAULT_MIN_SCALE; + if (zoomDouble != null) { + zoomFloat = zoomDouble.floatValue(); + } + result.success(pdfView.getPageLength(page, zoomFloat).doubleValue()); } } private void getPageSpacing(MethodCall methodCall, Result result) { if (methodCall.argument("pageIndex") != null) { int page = (int) methodCall.argument("pageIndex"); - result.success(pdfView.getPageSpacing(page)); + result.success(pdfView.getPageSpacing(page).doubleValue()); } } private void getCurrentYOffset(Result result) { - result.success(pdfView.getCurrentYOffset()); + double currentYOffsetDouble = pdfView.getCurrentYOffset(); + result.success(currentYOffsetDouble); } private void getCurrentXOffset(Result result) { - result.success(pdfView.getCurrentXOffset()); + double currentXOffsetDouble = pdfView.getCurrentXOffset(); + result.success(currentXOffsetDouble); } private void getSpacingPx(Result result) { @@ -267,14 +301,16 @@ private void getSpacingPx(Result result) { private void getPageHeight(MethodCall methodCall, Result result) { if (methodCall.argument("pageIndex") != null) { int page = (int) methodCall.argument("pageIndex"); - result.success(pdfView.getPageSize(page).getHeight()); + 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"); - result.success(pdfView.getPageSize(page).getWidth()); + double widthDouble = pdfView.getPageSize(page).getWidth(); + result.success(widthDouble); } } @@ -289,6 +325,7 @@ private void getPageSize(MethodCall methodCall, Result result) { } private void getZoom(Result result) { + double zoomDouble = pdfView.getZoom(); result.success(pdfView.getZoom()); } @@ -300,8 +337,12 @@ private void resetZoom(Result result) { private void zoomTo(MethodCall methodCall, Result result) { if (methodCall.argument("zoom") != null) { - float zoom = (float) methodCall.argument("zoom"); - pdfView.zoomTo(zoom); + Double zoomDouble = (Double) methodCall.argument("zoom"); + float zoomFloat = PDFView.DEFAULT_MIN_SCALE; + if (zoomDouble != null) { + zoomFloat = zoomDouble.floatValue(); + } + pdfView.zoomTo(zoomFloat); } result.success(true); From d880698ace40d352a558623b6e186576190a78f5 Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez <93cgutierrez@gmail.com> Date: Fri, 8 Sep 2023 13:56:36 -0500 Subject: [PATCH 7/8] AndroidPdfViewer:3.3.0-beta.3 change variable types --- lib/flutter_pdfview.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/flutter_pdfview.dart b/lib/flutter_pdfview.dart index b3668b14..9fca30c4 100644 --- a/lib/flutter_pdfview.dart +++ b/lib/flutter_pdfview.dart @@ -496,8 +496,8 @@ class PDFViewController { } //get spacing between pages, in pixels - Future getSpacingPx() async { - final double? spacing = await _channel.invokeMethod('getSpacingPx'); + Future getSpacingPx() async { + final int? spacing = await _channel.invokeMethod('getSpacingPx'); return spacing; } From 43cb45bb7feafc299178e92d7cb550646d65144e Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez <93cgutierrez@gmail.com> Date: Fri, 8 Sep 2023 16:37:33 -0500 Subject: [PATCH 8/8] control null Float --- .../plugins/pdfviewflutter/FlutterPDFView.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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 2c0644ef..77ea9d35 100644 --- a/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java +++ b/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java @@ -235,7 +235,9 @@ private void getSecondaryPageOffset(MethodCall methodCall, Result result) { if (zoomDouble != null) { zoomFloat = zoomDouble.floatValue(); } - result.success(pdfView.getSecondaryPageOffset(page, zoomFloat).doubleValue()); + Float secondaryPageOffset = pdfView.getSecondaryPageOffset(page, zoomFloat); + + result.success(secondaryPageOffset == null ? null : secondaryPageOffset.doubleValue()); } } @@ -247,8 +249,9 @@ private void getPageOffset(MethodCall methodCall, Result result) { if (zoomDouble != null) { zoomFloat = zoomDouble.floatValue(); } + Float pageOffset = pdfView.getPageOffset(page, zoomFloat); - result.success(pdfView.getPageOffset(page, zoomFloat).doubleValue()); + result.success(pageOffset == null ? null : pageOffset.doubleValue()); } } @@ -260,8 +263,9 @@ private void getPageSpacingWithZoom(MethodCall methodCall, Result result) { if (zoomDouble != null) { zoomFloat = zoomDouble.floatValue(); } + Float pageSpacing = pdfView.getPageSpacing(page, zoomFloat); - result.success(pdfView.getPageSpacing(page, zoomFloat).doubleValue()); + result.success(pageSpacing == null ? null : pdfView.getPageSpacing(page, zoomFloat).doubleValue()); } } @@ -273,14 +277,18 @@ private void getPageLength(MethodCall methodCall, Result result) { if (zoomDouble != null) { zoomFloat = zoomDouble.floatValue(); } - result.success(pdfView.getPageLength(page, zoomFloat).doubleValue()); + 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"); - result.success(pdfView.getPageSpacing(page).doubleValue()); + Float pageSpacing = pdfView.getPageSpacing(page); + + result.success(pageSpacing == null ? null : pageSpacing.doubleValue()); } }