diff --git a/android/build.gradle b/android/build.gradle index 0847f050..a814ae7e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -4,29 +4,35 @@ version '1.0-SNAPSHOT' buildscript { repositories { google() + //gradlePluginPortal() mavenCentral() + //jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:7.1.1' //3.2.1 //7.3.3 } } rootProject.allprojects { repositories { google() + //gradlePluginPortal() + mavenCentral() + //jcenter() } } apply plugin: 'com.android.library' android { - compileSdkVersion 30 + compileSdkVersion 29 defaultConfig { - minSdkVersion 16 + minSdkVersion 16 //21 testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' consumerProguardFiles 'proguard-rules.pro' + multiDexEnabled true } lintOptions { disable 'InvalidPackage' @@ -34,6 +40,10 @@ android { } dependencies { + // comment next line to run the app + // implementation files('C://flutter/bin/cache/artifacts/engine/android-x64/flutter.jar') + // implementation 'com.github.pires:obd-java-api:1.0' implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1' + // implementation 'com.android.support:multidex:2.0.1' } diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..e708b1c0 Binary files /dev/null and b/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..ec568929 --- /dev/null +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Feb 16 14:19:04 ART 2022 +distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/android/gradlew b/android/gradlew new file mode 100644 index 00000000..4f906e0c --- /dev/null +++ b/android/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/android/gradlew.bat b/android/gradlew.bat new file mode 100644 index 00000000..ac1b06f9 --- /dev/null +++ b/android/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega 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..49451f33 100644 --- a/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java +++ b/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java @@ -1,8 +1,24 @@ package io.endigo.plugins.pdfviewflutter; import android.content.Context; -import android.view.View; +import android.graphics.Color; import android.net.Uri; +import android.view.MotionEvent; +import android.view.View; + +import com.github.barteksc.pdfviewer.PDFView; +import com.github.barteksc.pdfviewer.PDFView.Configurator; +import com.github.barteksc.pdfviewer.link.LinkHandler; +import com.github.barteksc.pdfviewer.listener.OnErrorListener; +import com.github.barteksc.pdfviewer.listener.OnPageChangeListener; +import com.github.barteksc.pdfviewer.listener.OnPageErrorListener; +import com.github.barteksc.pdfviewer.listener.OnRenderListener; +import com.github.barteksc.pdfviewer.listener.OnTapListener; +import com.github.barteksc.pdfviewer.util.FitPolicy; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodCall; @@ -11,26 +27,21 @@ import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.platform.PlatformView; -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -import com.github.barteksc.pdfviewer.PDFView; -import com.github.barteksc.pdfviewer.PDFView.Configurator; -import com.github.barteksc.pdfviewer.listener.*; -import com.github.barteksc.pdfviewer.util.Constants; -import com.github.barteksc.pdfviewer.util.FitPolicy; - -import com.github.barteksc.pdfviewer.link.LinkHandler; - public class FlutterPDFView implements PlatformView, MethodCallHandler { private final PDFView pdfView; private final MethodChannel methodChannel; private final LinkHandler linkHandler; + + @SuppressWarnings("unchecked") FlutterPDFView(Context context, BinaryMessenger messenger, int id, Map params) { pdfView = new PDFView(context, null); + + String setBackgroundColor = getString(params, "setBackgroundColor"); + pdfView.setBackgroundColor(Color.parseColor('#'+setBackgroundColor)); //"#BB29BB" +// pdfView.setBackgroundColor(Color.TRANSPARENT); + final boolean preventLinkNavigation = getBoolean(params, "preventLinkNavigation"); methodChannel = new MethodChannel(messenger, "plugins.endigo.io/pdfview_" + id); @@ -49,6 +60,10 @@ else if (params.get("pdfData") != null) { } if (config != null) { + pdfView.setMaxZoom(getFloat(params,"setMaxZoom")); // default 3.0f + pdfView.setMidZoom(getFloat(params,"setMidZoom")); // default 1.75f + pdfView.setMinZoom(getFloat(params,"setMinZoom")); // default 1.0f + config .enableSwipe(getBoolean(params, "enableSwipe")) .swipeHorizontal(getBoolean(params, "swipeHorizontal")) @@ -59,9 +74,22 @@ else if (params.get("pdfData") != null) { .pageSnap(getBoolean(params, "pageSnap")) .pageFitPolicy(getFitPolicy(params)) .enableAnnotationRendering(true) - .linkHandler(linkHandler). - enableAntialiasing(false) - // .fitEachPage(getBoolean(params,"fitEachPage")) + .linkHandler(linkHandler) + + .enableAntialiasing(false) + .fitEachPage(getBoolean(params,"fitEachPage")) + .enableDoubletap(getBoolean(params,"enableDoubleTap")) + .defaultPage(getInt(params, "defaultPage")) + .spacing(getInt(params,"spacing")) + .onTap(new OnTapListener() { +// Log.i('onTap-native','onTap'); + + @Override + public boolean onTap(MotionEvent e) { + methodChannel.invokeMethod("onTap",null); + return false; + } + }) .onPageChange(new OnPageChangeListener() { @Override public void onPageChanged(int page, int total) { @@ -70,14 +98,16 @@ public void onPageChanged(int page, int total) { args.put("total", total); methodChannel.invokeMethod("onPageChanged", args); } - }).onError(new OnErrorListener() { + }) + .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() { + }) + .onPageError(new OnPageErrorListener() { @Override public void onPageError(int page, Throwable t) { Map args = new HashMap<>(); @@ -85,17 +115,20 @@ public void onPageError(int page, Throwable t) { args.put("error", t.toString()); methodChannel.invokeMethod("onPageError", args); } - }).onRender(new OnRenderListener() { + }) + .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(); + }).load(); } } + + @Override public View getView() { return pdfView; @@ -175,17 +208,21 @@ public void dispose() { methodChannel.setMethodCallHandler(null); } - boolean getBoolean(Map params, String key) { + private boolean getBoolean(Map params, String key) { return params.containsKey(key) ? (boolean) params.get(key) : false; } - String getString(Map params, String key) { + private String getString(Map params, String key) { return params.containsKey(key) ? (String) params.get(key) : ""; } - int getInt(Map params, String key) { + private int getInt(Map params, String key) { return params.containsKey(key) ? (int) params.get(key) : 0; } + private float getFloat(Map params, String key) { + double d = (double)params.get(key); + return params.containsKey(key) ? (float)d : 0.0f; + } FitPolicy getFitPolicy(Map params) { String fitPolicy = getString(params, "fitPolicy"); diff --git a/android/src/main/java/io/endigo/plugins/pdfviewflutter/PDFViewFactory.java b/android/src/main/java/io/endigo/plugins/pdfviewflutter/PDFViewFactory.java index 23badec3..f0f3eedf 100644 --- a/android/src/main/java/io/endigo/plugins/pdfviewflutter/PDFViewFactory.java +++ b/android/src/main/java/io/endigo/plugins/pdfviewflutter/PDFViewFactory.java @@ -1,11 +1,13 @@ package io.endigo.plugins.pdfviewflutter; import android.content.Context; + +import java.util.Map; + import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.StandardMessageCodec; import io.flutter.plugin.platform.PlatformView; import io.flutter.plugin.platform.PlatformViewFactory; -import java.util.Map; public class PDFViewFactory extends PlatformViewFactory { private final BinaryMessenger messenger; @@ -15,6 +17,7 @@ public PDFViewFactory(BinaryMessenger messenger) { this.messenger = messenger; } + @SuppressWarnings("unchecked") @Override public PlatformView create(Context context, int id, Object args) { diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 7e126f93..8665ef51 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 28 + compileSdkVersion 31 lintOptions { disable 'InvalidPackage' diff --git a/example/android/build.gradle b/example/android/build.gradle index bb8a3038..3584b7d9 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:7.1.1' //3.2.1 //7.3.0-alpha03 //7.3.3 } } @@ -19,8 +19,6 @@ allprojects { rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" -} -subprojects { project.evaluationDependsOn(':app') } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 2819f022..595fb867 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 9367d483..8d4492f9 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 9.0 diff --git a/example/ios/Flutter/Flutter.podspec b/example/ios/Flutter/Flutter.podspec index 5ca30416..663d5b29 100644 --- a/example/ios/Flutter/Flutter.podspec +++ b/example/ios/Flutter/Flutter.podspec @@ -1,18 +1,18 @@ # # NOTE: This podspec is NOT to be published. It is only used as a local source! +# This is a generated file; do not edit or check into version control. # Pod::Spec.new do |s| s.name = 'Flutter' s.version = '1.0.0' s.summary = 'High-performance, high-fidelity mobile apps.' - s.description = <<-DESC -Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS. - DESC s.homepage = 'https://flutter.io' s.license = { :type => 'MIT' } s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s } - s.ios.deployment_target = '8.0' - s.vendored_frameworks = 'Flutter.framework' + s.ios.deployment_target = '9.0' + # Framework linking is handled by Flutter tooling, not CocoaPods. + # Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs. + s.vendored_frameworks = 'path/to/nothing' end diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index 4750ebc9..08109ff3 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -1,14 +1,14 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=/Users/endigo/Projects/sdk/flutter" -export "FLUTTER_APPLICATION_PATH=/Users/endigo/Projects/dart/flutter_pdfview/example" +export "FLUTTER_ROOT=/Users/hola/dev/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/hola/dev/flutter_pdfview/example" export "COCOAPODS_PARALLEL_CODE_SIGN=true" -export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_TARGET=/Users/hola/dev/flutter_pdfview/example/lib/main.dart" export "FLUTTER_BUILD_DIR=build" -export "SYMROOT=${SOURCE_ROOT}/../build/ios" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=1.0.0" +export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==" export "DART_OBFUSCATION=false" -export "TRACK_WIDGET_CREATION=false" +export "TRACK_WIDGET_CREATION=true" export "TREE_SHAKE_ICONS=false" -export "PACKAGE_CONFIG=.packages" +export "PACKAGE_CONFIG=/Users/hola/dev/flutter_pdfview/example/.dart_tool/package_config.json" diff --git a/example/ios/Podfile b/example/ios/Podfile index b30a428b..1e8c3c90 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -10,81 +10,32 @@ project 'Runner', { 'Release' => :release, } -def parse_KV_file(file, separator='=') - file_abs_path = File.expand_path(file) - if !File.exists? file_abs_path - return []; +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" end - generated_key_values = {} - skip_line_start_symbols = ["#", "/"] - File.foreach(file_abs_path) do |line| - next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ } - plugin = line.split(pattern=separator) - if plugin.length == 2 - podname = plugin[0].strip() - path = plugin[1].strip() - podpath = File.expand_path("#{path}", file_abs_path) - generated_key_values[podname] = podpath - else - puts "Invalid plugin specification: #{line}" - end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches end - generated_key_values + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" end +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + target 'Runner' do use_frameworks! use_modular_headers! - - # Flutter Pod - copied_flutter_dir = File.join(__dir__, 'Flutter') - copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework') - copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec') - unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path) - # Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet. - # That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration. - # CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist. - - generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig') - unless File.exist?(generated_xcode_build_settings_path) - raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first" - end - generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path) - cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR']; - - unless File.exist?(copied_framework_path) - FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir) - end - unless File.exist?(copied_podspec_path) - FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir) - end - end - - # Keep pod path relative so it can be checked into Podfile.lock. - pod 'Flutter', :path => 'Flutter' - - # Plugin Pods - - # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock - # referring to absolute paths on developers' machines. - system('rm -rf .symlinks') - system('mkdir -p .symlinks/plugins') - plugin_pods = parse_KV_file('../.flutter-plugins') - plugin_pods.each do |name, path| - symlink = File.join('.symlinks', 'plugins', name) - File.symlink(path, symlink) - pod name, :path => File.join(symlink, 'ios') - end + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) end -# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system. -install! 'cocoapods', :disable_input_output_paths => true - post_install do |installer| installer.pods_project.targets.each do |target| - target.build_configurations.each do |config| - config.build_settings['ENABLE_BITCODE'] = 'NO' - end + flutter_additional_ios_build_settings(target) end end diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 73e04f25..ca25629f 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -4,17 +4,11 @@ PODS: - Flutter - path_provider (0.0.1): - Flutter - - path_provider_linux (0.0.1): - - Flutter - - path_provider_macos (0.0.1): - - Flutter DEPENDENCIES: - Flutter (from `Flutter`) - flutter_pdfview (from `.symlinks/plugins/flutter_pdfview/ios`) - path_provider (from `.symlinks/plugins/path_provider/ios`) - - path_provider_linux (from `.symlinks/plugins/path_provider_linux/ios`) - - path_provider_macos (from `.symlinks/plugins/path_provider_macos/ios`) EXTERNAL SOURCES: Flutter: @@ -23,18 +17,12 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/flutter_pdfview/ios" path_provider: :path: ".symlinks/plugins/path_provider/ios" - path_provider_linux: - :path: ".symlinks/plugins/path_provider_linux/ios" - path_provider_macos: - :path: ".symlinks/plugins/path_provider_macos/ios" SPEC CHECKSUMS: - Flutter: 0e3d915762c693b495b44d77113d4970485de6ec + Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a flutter_pdfview: 25f53dd6097661e6395b17de506e6060585946bd path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c - path_provider_linux: 4d630dc393e1f20364f3e3b4a2ff41d9674a84e4 - path_provider_macos: f760a3c5b04357c380e2fddb6f9db6f3015897e0 -PODFILE CHECKSUM: 1b66dae606f75376c5f2135a8290850eeb09ae83 +PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c -COCOAPODS: 1.9.3 +COCOAPODS: 1.11.2 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index d6ee47ce..1b5ae465 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -14,6 +14,8 @@ 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; D94B61CFB9FC83B1FA0D2F3E /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD3D6C721F34AF3231CDFB0C /* Pods_Runner.framework */; }; + EAB01CE727C8043E00651D79 /* PDFViewFlutterPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = EAB01CE327C8043E00651D79 /* PDFViewFlutterPlugin.m */; }; + EAB01CE827C8043E00651D79 /* FlutterPDFView.m in Sources */ = {isa = PBXBuildFile; fileRef = EAB01CE627C8043E00651D79 /* FlutterPDFView.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -47,6 +49,10 @@ 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; CD3D6C721F34AF3231CDFB0C /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + EAB01CE327C8043E00651D79 /* PDFViewFlutterPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PDFViewFlutterPlugin.m; sourceTree = ""; }; + EAB01CE427C8043E00651D79 /* PDFViewFlutterPlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PDFViewFlutterPlugin.h; sourceTree = ""; }; + EAB01CE527C8043E00651D79 /* FlutterPDFView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlutterPDFView.h; sourceTree = ""; }; + EAB01CE627C8043E00651D79 /* FlutterPDFView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FlutterPDFView.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -104,6 +110,10 @@ 97C146F01CF9000F007C117D /* Runner */ = { isa = PBXGroup; children = ( + EAB01CE527C8043E00651D79 /* FlutterPDFView.h */, + EAB01CE627C8043E00651D79 /* FlutterPDFView.m */, + EAB01CE427C8043E00651D79 /* PDFViewFlutterPlugin.h */, + EAB01CE327C8043E00651D79 /* PDFViewFlutterPlugin.m */, 97C146FA1CF9000F007C117D /* Main.storyboard */, 97C146FD1CF9000F007C117D /* Assets.xcassets */, 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, @@ -163,7 +173,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = "The Chromium Authors"; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -261,9 +271,14 @@ files = ( ); inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/flutter_pdfview/flutter_pdfview.framework", + "${BUILT_PRODUCTS_DIR}/path_provider/path_provider.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_pdfview.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -277,7 +292,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + EAB01CE727C8043E00651D79 /* PDFViewFlutterPlugin.m in Sources */, 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, + EAB01CE827C8043E00651D79 /* FlutterPDFView.m in Sources */, 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -345,7 +362,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -426,7 +443,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -475,7 +492,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a16..919434a6 100644 --- a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index a28140cf..3db53b6e 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ with WidgetsBindingObserver { int? currentPage = 0; bool isReady = false; String errorMessage = ''; + String title = "Document"; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text("Document"), + title: Text(title), actions: [ IconButton( - icon: Icon(Icons.share), - onPressed: () {}, - ), - ], - ), - body: Stack( - children: [ - PDFView( - filePath: widget.path, - enableSwipe: true, - swipeHorizontal: true, - autoSpacing: false, - pageFling: true, - pageSnap: true, - defaultPage: currentPage!, - fitPolicy: FitPolicy.BOTH, - preventLinkNavigation: - false, // if set to true the link is handled in flutter - onRender: (_pages) { - setState(() { - pages = _pages; - isReady = true; - }); - }, - onError: (error) { - setState(() { - errorMessage = error.toString(); - }); - print(error.toString()); - }, - onPageError: (page, error) { - setState(() { - errorMessage = '$page: ${error.toString()}'; - }); - print('$page: ${error.toString()}'); - }, - onViewCreated: (PDFViewController pdfViewController) { - _controller.complete(pdfViewController); - }, - onLinkHandler: (String? uri) { - print('goto uri: $uri'); - }, - onPageChanged: (int? page, int? total) { - print('page change: $page/$total'); - setState(() { - currentPage = page; - }); + icon: Icon(Icons.refresh_rounded), + onPressed: () async { + PDFViewController controller = await _controller.future; + // await controller.refreshDrawableState(); }, ), - errorMessage.isEmpty - ? !isReady - ? Center( - child: CircularProgressIndicator(), - ) - : Container() - : Center( - child: Text(errorMessage), - ) ], ), + body: GestureDetector( + onTap: () => print('onTap'), + onTapCancel: () => print('onTapCancel'), + onTapDown: (_) => print('onTapDown'), + onTapUp: (_) => print('onTapUp'), + child: PDFView( + filePath: widget.path, + // setMaxZoom: 5, + // setMinZoom: 0.8, + enableSwipe: true, + // swipeHorizontal: true, + autoSpacing: false, + pageFling: false, + pageSnap: false, + spacing: 10, + defaultPage: currentPage!, + fitPolicy: FitPolicy.BOTH, + enableDoubleTap: true, + setBackgroundColor: Colors.grey, + preventLinkNavigation: + false, // if set to true the link is handled in flutter + onTap: () { + setState(() { + title = 'Pdf Doc'; + }); + print('onTap callback'); + }, + onRender: (_pages) { + setState(() { + pages = _pages; + isReady = true; + }); + }, + onError: (error) { + setState(() { + errorMessage = error.toString(); + }); + print(error.toString()); + }, + onPageError: (page, error) { + setState(() { + errorMessage = '$page: ${error.toString()}'; + }); + print('$page: ${error.toString()}'); + }, + onViewCreated: (PDFViewController pdfViewController) { + _controller.complete(pdfViewController); + }, + onLinkHandler: (String? uri) { + print('goto uri: $uri'); + }, + onPageChanged: (int? page, int? total) { + print('page change: $page/$total'); + setState(() { + currentPage = page; + }); + }, + ), + ), + // errorMessage.isEmpty + // ? !isReady + // ? Center( + // child: CircularProgressIndicator(), + // ) + // : Container() + // : Center( + // child: Text(errorMessage), + // ) + floatingActionButton: FutureBuilder( future: _controller.future, builder: (context, AsyncSnapshot snapshot) { diff --git a/example/pubspec.lock b/example/pubspec.lock index 527ff16e..8b3da4f9 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -21,14 +21,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -94,14 +94,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.11" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" path: dependency: transitive description: @@ -211,7 +218,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.8" typed_data: dependency: transitive description: @@ -225,7 +232,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" win32: dependency: transitive description: @@ -241,5 +248,5 @@ packages: source: hosted version: "0.2.0" sdks: - dart: ">=2.13.0 <3.0.0" + dart: ">=2.14.0 <3.0.0" flutter: ">=2.2.0" diff --git a/ios/Classes/FlutterPDFView.m b/ios/Classes/FlutterPDFView.m index c55c5af6..39239f9a 100644 --- a/ios/Classes/FlutterPDFView.m +++ b/ios/Classes/FlutterPDFView.m @@ -83,7 +83,19 @@ - (instancetype)initWithFrame:(CGRect)frame } else { _pdfView.autoresizesSubviews = YES; _pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth; + + // TODO: change this to args value _pdfView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0]; + + // this is to enable double tap to zoom + _pdfView.enableDataDetectors = [args[@"enableDoubleTap"] boolValue]; + + UITapGestureRecognizer *recognizer = + [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; + [recognizer setNumberOfTapsRequired:1]; + + [_pdfView addGestureRecognizer: recognizer]; + BOOL swipeHorizontal = [args[@"swipeHorizontal"] boolValue]; if (swipeHorizontal) { _pdfView.displayDirection = kPDFDisplayDirectionHorizontal; @@ -109,8 +121,14 @@ - (instancetype)initWithFrame:(CGRect)frame PDFPage* page = [document pageAtIndex: defaultPage]; [_pdfView goToPage: page]; + // _pdfView.minScaleFactor = [args[@"setMinZoom"] doubleValue]; _pdfView.minScaleFactor = _pdfView.scaleFactorForSizeToFit; - _pdfView.maxScaleFactor = 4.0; + _pdfView.maxScaleFactor = [args[@"setMaxZoom"] doubleValue]; // 4.0; + + // set the initial scale to minimum that is fit to screen. + _pdfView.scaleFactor = _pdfView.minScaleFactor; + // TODO: this can work? + // _pdfView.contentScaleFactor = [args[@"setMidZoom"] doubleValue];; dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf handleRenderCompleted:[NSNumber numberWithUnsignedLong: [document pageCount]]]; @@ -194,5 +212,8 @@ - (void)PDFViewWillClickOnLink:(PDFView *)sender } [_channel invokeMethod:@"onLinkHandler" arguments:url.absoluteString]; } +- (void) handleTap: (UITapGestureRecognizer *)recognizer { + [_channel invokeMethod:@"onTap" arguments:nil]; +} @end diff --git a/lib/flutter_pdfview.dart b/lib/flutter_pdfview.dart index b3741512..0eae914e 100644 --- a/lib/flutter_pdfview.dart +++ b/lib/flutter_pdfview.dart @@ -3,8 +3,9 @@ import 'dart:typed_data'; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +// import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; -import 'package:flutter/widgets.dart'; typedef PDFViewCreatedCallback = void Function(PDFViewController controller); typedef RenderCallback = void Function(int? pages); @@ -38,6 +39,13 @@ class PDFView extends StatefulWidget { this.defaultPage = 0, this.fitPolicy = FitPolicy.WIDTH, this.preventLinkNavigation = false, + this.onTap, + this.spacing = 0, + this.enableDoubleTap = true, + this.setBackgroundColor = Colors.white, + this.setMaxZoom = 3.0, + this.setMidZoom = 1.75, + this.setMinZoom = 1.0, }) : assert(filePath != null || pdfData != null), super(key: key); @@ -46,12 +54,21 @@ class PDFView extends StatefulWidget { /// If not null invoked once the web view is created. final PDFViewCreatedCallback? onViewCreated; + final RenderCallback? onRender; + final PageChangedCallback? onPageChanged; + final ErrorCallback? onError; + + /// Works on [Android] final PageErrorCallback? onPageError; + final LinkHandlerCallback? onLinkHandler; + /// Works on [Android] + final VoidCallback? onTap; + /// Which gestures should be consumed by the pdf view. /// /// It is possible for other gesture recognizers to be competing with the pdf view on pointer @@ -70,14 +87,52 @@ class PDFView extends StatefulWidget { final bool enableSwipe; final bool swipeHorizontal; final String? password; + + /// Works on [Android] final bool nightMode; final bool autoSpacing; + + /// minimum swipe to change the page final bool pageFling; + + /// Works on [Android] + /// + /// if [true] automatic center the page + /// + /// if [false] you can stop betwen two pages final bool pageSnap; + + /// initial page to show final int defaultPage; + + /// Works on [Android] final FitPolicy fitPolicy; final bool fitEachPage; final bool preventLinkNavigation; + + /// Works on [Android] + /// + /// space betwen the pages (arround each page) + final int spacing; + + /// Works on [Android] + /// + /// for zoom-in-out + final bool enableDoubleTap; + + /// Works on [Android] + final Color setBackgroundColor; + + /// Works on [Android] + final double setMaxZoom; + + /// Works on [Android] + /// + /// for double tap (middle step) + final double setMidZoom; + + /// Works on [Android] + final double setMinZoom; } class _PDFViewState extends State { @@ -86,6 +141,40 @@ class _PDFViewState extends State { @override Widget build(BuildContext context) { if (defaultTargetPlatform == TargetPlatform.android) { + // // aded by lcyper + + // return PlatformViewLink( + // surfaceFactory: (context, controller) { + // return AndroidViewSurface( + // controller: controller as AndroidViewController, + // gestureRecognizers: widget.gestureRecognizers ?? + // >{}, + // hitTestBehavior: PlatformViewHitTestBehavior.opaque, + // ); + // }, + // viewType: 'plugins.endigo.io/pdfview', + // onCreatePlatformView: (PlatformViewCreationParams params) { + // // final PDFViewController controller = PDFViewController._(id, widget); + // // _controller.complete(controller); + // // if (widget.onViewCreated != null) { + // // widget.onViewCreated!(controller); + // // } + // return PlatformViewsService.initSurfaceAndroidView( + // id: params.id, + // viewType: 'plugins.endigo.io/pdfview', + // layoutDirection: TextDirection.ltr, + // creationParams: _CreationParams.fromWidget(widget).toMap(), + // creationParamsCodec: const StandardMessageCodec(), + // onFocus: () { + // params.onFocusChanged(true); + // }, + // ) + // ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated) + // ..create(); + // }, + // ); + // // until here + return AndroidView( viewType: 'plugins.endigo.io/pdfview', onPlatformViewCreated: _onPlatformViewCreated, @@ -155,44 +244,65 @@ 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({ + required this.enableSwipe, + required this.swipeHorizontal, + this.password, + required this.nightMode, + required this.autoSpacing, + required this.pageFling, + required this.pageSnap, + required this.defaultPage, + required this.fitPolicy, + required this.fitEachPage, + required this.preventLinkNavigation, + required this.spacing, + required this.enableDoubleTap, + required this.setBackgroundColor, + required this.setMaxZoom, + required this.setMidZoom, + required this.setMinZoom, + }); static _PDFViewSettings fromWidget(PDFView widget) { return _PDFViewSettings( - enableSwipe: widget.enableSwipe, - swipeHorizontal: widget.swipeHorizontal, - password: widget.password, - nightMode: widget.nightMode, - autoSpacing: widget.autoSpacing, - pageFling: widget.pageFling, - pageSnap: widget.pageSnap, - defaultPage: widget.defaultPage, - fitPolicy: widget.fitPolicy, - preventLinkNavigation: widget.preventLinkNavigation); + enableSwipe: widget.enableSwipe, + swipeHorizontal: widget.swipeHorizontal, + password: widget.password, + nightMode: widget.nightMode, + autoSpacing: widget.autoSpacing, + pageFling: widget.pageFling, + pageSnap: widget.pageSnap, + defaultPage: widget.defaultPage, + fitPolicy: widget.fitPolicy, + fitEachPage: widget.fitEachPage, + preventLinkNavigation: widget.preventLinkNavigation, + spacing: widget.spacing, + enableDoubleTap: widget.enableDoubleTap, + setBackgroundColor: widget.setBackgroundColor, + setMaxZoom: widget.setMaxZoom, + setMidZoom: widget.setMidZoom, + setMinZoom: widget.setMinZoom, + ); } - final bool? enableSwipe; - final bool? swipeHorizontal; + final bool enableSwipe; + final bool swipeHorizontal; final String? password; - final bool? nightMode; - final bool? autoSpacing; - final bool? pageFling; - final bool? pageSnap; - final int? defaultPage; - final FitPolicy? fitPolicy; - final bool? fitEachPage; - final bool? preventLinkNavigation; + final bool nightMode; + final bool autoSpacing; + final bool pageFling; + final bool pageSnap; + final int defaultPage; + final FitPolicy fitPolicy; + final bool fitEachPage; + final bool preventLinkNavigation; + final int spacing; + final bool enableDoubleTap; + final Color setBackgroundColor; + final double setMaxZoom; + final double setMidZoom; + final double setMinZoom; Map toMap() { return { @@ -206,7 +316,14 @@ class _PDFViewSettings { 'defaultPage': defaultPage, 'fitPolicy': fitPolicy.toString(), 'fitEachPage': fitEachPage, - 'preventLinkNavigation': preventLinkNavigation + 'preventLinkNavigation': preventLinkNavigation, + 'spacing': spacing, + 'enableDoubleTap': enableDoubleTap, + // convert Color to hex string + 'setBackgroundColor': setBackgroundColor.value.toRadixString(16), + 'setMaxZoom': setMaxZoom, + 'setMidZoom': setMidZoom, + 'setMinZoom': setMinZoom, }; } @@ -275,6 +392,13 @@ class PDFViewController { _widget.onLinkHandler!(call.arguments); } + return null; + + case 'onTap': + if (_widget.onTap != null) { + _widget.onTap!(); + } + return null; } throw MissingPluginException( diff --git a/pubspec.lock b/pubspec.lock index f9edb7f8..794adbc9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -21,14 +21,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -66,14 +66,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.11" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" path: dependency: transitive description: @@ -127,7 +134,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.8" typed_data: dependency: transitive description: @@ -141,7 +148,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=2.14.0 <3.0.0" flutter: ">=2.2.0"