Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import 'package:flutter_pdfview/flutter_pdfview.dart';
| pageFling | ✅ | ✅ | `true` |
| pageSnap | ✅ | ❌ | `true` |
| preventLinkNavigation | ✅ | ✅ | `false` |
| scrollHandle | ✅ | ❌ | `true` |

## Controller Options

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.github.barteksc.pdfviewer.util.FitPolicy;

import com.github.barteksc.pdfviewer.link.LinkHandler;
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle;

public class FlutterPDFView implements PlatformView, MethodCallHandler {
private final PDFView pdfView;
Expand Down Expand Up @@ -93,6 +94,8 @@ public void onInitiallyRendered(int pages) {
methodChannel.invokeMethod("onRender", args);
}
}).enableDoubletap(true).defaultPage(getInt(params, "defaultPage")).load();
if(getBoolean(params, "scrollHandle"))
config.scrollHandle(new DefaultScrollHandle(context));
}
}

Expand Down Expand Up @@ -133,7 +136,12 @@ void getCurrentPage(Result result) {
void setPage(MethodCall call, Result result) {
if (call.argument("page") != null) {
int page = (int) call.argument("page");
pdfView.jumpTo(page);
if(call.argument("animation")){
pdfView.jumpTo(pdfView.getCurrentPage(), false);
pdfView.jumpTo(page, true);
} else {
pdfView.jumpTo(page);
}
}

result.success(true);
Expand Down
63 changes: 36 additions & 27 deletions lib/flutter_pdfview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class PDFView extends StatefulWidget {
this.defaultPage = 0,
this.fitPolicy = FitPolicy.WIDTH,
this.preventLinkNavigation = false,
})
: assert(filePath != null || pdfData != null),
this.scrollHandle = true,
}) : assert(filePath != null || pdfData != null),
super(key: key);

@override
Expand Down Expand Up @@ -80,19 +80,22 @@ class PDFView extends StatefulWidget {
final FitPolicy fitPolicy;
final bool fitEachPage;
final bool preventLinkNavigation;
final bool scrollHandle;
}

class _PDFViewState extends State<PDFView> {
final Completer<PDFViewController> _controller =
Completer<PDFViewController>();
Completer<PDFViewController>();

@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 ??
Expand All @@ -108,9 +111,8 @@ class _PDFViewState extends State<PDFView> {
creationParams: _CreationParams.fromWidget(widget).toMap(),
creationParamsCodec: const StandardMessageCodec(),
)
..addOnPlatformViewCreatedListener(params
.onPlatformViewCreated)..addOnPlatformViewCreatedListener((
int id) {
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
..addOnPlatformViewCreatedListener((int id) {
_onPlatformViewCreated(id);
})
..create();
Expand Down Expand Up @@ -141,7 +143,7 @@ class _PDFViewState extends State<PDFView> {
void didUpdateWidget(PDFView oldWidget) {
super.didUpdateWidget(oldWidget);
_controller.future.then(
(PDFViewController controller) => controller._updateWidget(widget));
(PDFViewController controller) => controller._updateWidget(widget));
}
}

Expand Down Expand Up @@ -178,17 +180,19 @@ 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.enableSwipe,
this.swipeHorizontal,
this.password,
this.nightMode,
this.autoSpacing,
this.pageFling,
this.pageSnap,
this.defaultPage,
this.fitPolicy,
this.fitEachPage,
this.preventLinkNavigation,
this.scrollHandle});

static _PDFViewSettings fromWidget(PDFView widget) {
return _PDFViewSettings(
Expand All @@ -201,7 +205,8 @@ class _PDFViewSettings {
pageSnap: widget.pageSnap,
defaultPage: widget.defaultPage,
fitPolicy: widget.fitPolicy,
preventLinkNavigation: widget.preventLinkNavigation);
preventLinkNavigation: widget.preventLinkNavigation,
scrollHandle: widget.scrollHandle);
}

final bool? enableSwipe;
Expand All @@ -215,6 +220,7 @@ class _PDFViewSettings {
final FitPolicy? fitPolicy;
final bool? fitEachPage;
final bool? preventLinkNavigation;
final bool? scrollHandle;

Map<String, dynamic> toMap() {
return <String, dynamic>{
Expand All @@ -228,7 +234,8 @@ class _PDFViewSettings {
'defaultPage': defaultPage,
'fitPolicy': fitPolicy.toString(),
'fitEachPage': fitEachPage,
'preventLinkNavigation': preventLinkNavigation
'preventLinkNavigation': preventLinkNavigation,
'scrollHandle': scrollHandle,
};
}

Expand All @@ -251,9 +258,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);
}
Expand Down Expand Up @@ -312,10 +320,11 @@ class PDFViewController {
return currentPage;
}

Future<bool?> setPage(int page) async {
Future<bool?> setPage(int page, {bool animation = false}) async {
final bool? isSet =
await _channel.invokeMethod('setPage', <String, dynamic>{
await _channel.invokeMethod('setPage', <String, dynamic>{
'page': page,
'animation': animation,
});
return isSet;
}
Expand Down