diff --git a/android/build.gradle b/android/build.gradle
index 0847f050..97c50c18 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -34,6 +34,6 @@ android {
}
dependencies {
- implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
+ implementation 'com.github.mhiew:android-pdf-viewer:3.2.0-beta.1'
}
diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml
index affaa3a4..422c4de7 100644
--- a/android/src/main/AndroidManifest.xml
+++ b/android/src/main/AndroidManifest.xml
@@ -1,3 +1,4 @@
+
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..7ffd31d5 100644
--- a/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java
+++ b/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java
@@ -3,7 +3,7 @@
import android.content.Context;
import android.view.View;
import android.net.Uri;
-
+import android.graphics.Color;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
@@ -30,9 +30,12 @@ public class FlutterPDFView implements PlatformView, MethodCallHandler {
@SuppressWarnings("unchecked")
FlutterPDFView(Context context, BinaryMessenger messenger, int id, Map params) {
+ System.out.println(params);
+ System.out.println("Hello, World!");
+
pdfView = new PDFView(context, null);
final boolean preventLinkNavigation = getBoolean(params, "preventLinkNavigation");
-
+ pdfView.setBackgroundColor(Color.parseColor(getString(params, "backgroundColor")));
methodChannel = new MethodChannel(messenger, "plugins.endigo.io/pdfview_" + id);
methodChannel.setMethodCallHandler(this);
@@ -49,6 +52,7 @@ else if (params.get("pdfData") != null) {
}
if (config != null) {
+
config
.enableSwipe(getBoolean(params, "enableSwipe"))
.swipeHorizontal(getBoolean(params, "swipeHorizontal"))
@@ -57,6 +61,10 @@ else if (params.get("pdfData") != null) {
.autoSpacing(getBoolean(params, "autoSpacing"))
.pageFling(getBoolean(params, "pageFling"))
.pageSnap(getBoolean(params, "pageSnap"))
+ .spacing(getInt(params,"spacingPx"))
+ // .setBackground(Color.valueOf(0xffff0000))
+ .enableAntialiasing(true)
+ // .onDraw(this)
.pageFitPolicy(getFitPolicy(params))
.enableAnnotationRendering(true)
.linkHandler(linkHandler).
@@ -100,7 +108,7 @@ public void onInitiallyRendered(int pages) {
public View getView() {
return pdfView;
}
-
+
@Override
public void onMethodCall(MethodCall methodCall, Result result) {
switch (methodCall.method) {
diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh
index b6254afd..095a88a7 100755
--- a/example/ios/Flutter/flutter_export_environment.sh
+++ b/example/ios/Flutter/flutter_export_environment.sh
@@ -1,14 +1,13 @@
#!/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/theutsavg/Downloads/sdk/flutter"
+export "FLUTTER_APPLICATION_PATH=/Users/theutsavg/Documents/Projects/opensource/flutter_pdfview/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
-export "FLUTTER_TARGET=/Users/endigo/Projects/dart/flutter_pdfview/example/lib/main.dart"
+export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1.0.0"
-export "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_OBFUSCATION=false"
-export "TRACK_WIDGET_CREATION=true"
+export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
-export "PACKAGE_CONFIG=/Users/endigo/Projects/dart/flutter_pdfview/example/.dart_tool/package_config.json"
+export "PACKAGE_CONFIG=.dart_tool/package_config.json"
diff --git a/lib/flutter_pdfview.dart b/lib/flutter_pdfview.dart
index 5e0a1b33..8ba86db8 100644
--- a/lib/flutter_pdfview.dart
+++ b/lib/flutter_pdfview.dart
@@ -3,6 +3,7 @@ import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
+import 'package:flutter/material.dart' hide Widget;
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart';
@@ -17,7 +18,7 @@ typedef LinkHandlerCallback = void Function(String? uri);
enum FitPolicy { WIDTH, HEIGHT, BOTH }
class PDFView extends StatefulWidget {
- const PDFView({
+ PDFView({
Key? key,
this.filePath,
this.pdfData,
@@ -38,9 +39,14 @@ class PDFView extends StatefulWidget {
this.fitEachPage = true,
this.defaultPage = 0,
this.fitPolicy = FitPolicy.WIDTH,
+ this.pageSpacing = 8.0,
this.preventLinkNavigation = false,
- })
- : assert(filePath != null || pdfData != null),
+ this.backgroundColor = Colors.grey,
+ }) : assert(filePath != null || pdfData != null),
+ assert(
+ autoSpacing != false || pageSpacing != 0,
+ 'Either use custom spacing or auto spacing',
+ ),
super(key: key);
@override
@@ -80,19 +86,23 @@ class PDFView extends StatefulWidget {
final FitPolicy fitPolicy;
final bool fitEachPage;
final bool preventLinkNavigation;
+ final num pageSpacing;
+ final Color backgroundColor;
}
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 ??
@@ -108,9 +118,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();
@@ -141,7 +150,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));
}
}
@@ -178,9 +187,11 @@ class _CreationParams {
}
class _PDFViewSettings {
- _PDFViewSettings({this.enableSwipe,
+ _PDFViewSettings({
+ this.enableSwipe,
this.swipeHorizontal,
this.password,
+ required this.pageSpacing,
this.nightMode,
this.autoSpacing,
this.pageFling,
@@ -188,7 +199,9 @@ class _PDFViewSettings {
this.defaultPage,
this.fitPolicy,
this.fitEachPage,
- this.preventLinkNavigation});
+ this.backgroundColor,
+ this.preventLinkNavigation,
+ });
static _PDFViewSettings fromWidget(PDFView widget) {
return _PDFViewSettings(
@@ -200,6 +213,9 @@ class _PDFViewSettings {
pageFling: widget.pageFling,
pageSnap: widget.pageSnap,
defaultPage: widget.defaultPage,
+ pageSpacing: widget.pageSpacing,
+ backgroundColor: widget.backgroundColor,
+ fitEachPage: widget.fitEachPage,
fitPolicy: widget.fitPolicy,
preventLinkNavigation: widget.preventLinkNavigation);
}
@@ -215,6 +231,8 @@ class _PDFViewSettings {
final FitPolicy? fitPolicy;
final bool? fitEachPage;
final bool? preventLinkNavigation;
+ final num pageSpacing;
+ final Color? backgroundColor;
Map toMap() {
return {
@@ -223,11 +241,14 @@ class _PDFViewSettings {
'password': password,
'nightMode': nightMode,
'autoSpacing': autoSpacing,
+ 'spacingPx': pageSpacing.toInt(),
'pageFling': pageFling,
'pageSnap': pageSnap,
'defaultPage': defaultPage,
'fitPolicy': fitPolicy.toString(),
'fitEachPage': fitEachPage,
+ 'backgroundColor':
+ '#${backgroundColor?.value.toRadixString(16).substring(2)}',
'preventLinkNavigation': preventLinkNavigation
};
}
@@ -251,9 +272,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);
}
@@ -314,7 +336,7 @@ class PDFViewController {
Future setPage(int page) async {
final bool? isSet =
- await _channel.invokeMethod('setPage', {
+ await _channel.invokeMethod('setPage', {
'page': page,
});
return isSet;