diff --git a/lib/flutter_pdfview.dart b/lib/flutter_pdfview.dart index a448b20c..5e0a1b33 100644 --- a/lib/flutter_pdfview.dart +++ b/lib/flutter_pdfview.dart @@ -3,9 +3,9 @@ import 'dart:typed_data'; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; -import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; +import 'package:flutter/rendering.dart'; typedef PDFViewCreatedCallback = void Function(PDFViewController controller); typedef RenderCallback = void Function(int? pages); @@ -39,8 +39,8 @@ class PDFView extends StatefulWidget { this.defaultPage = 0, this.fitPolicy = FitPolicy.WIDTH, this.preventLinkNavigation = false, - this.useHybridComposition = false, - }) : assert(filePath != null || pdfData != null), + }) + : assert(filePath != null || pdfData != null), super(key: key); @override @@ -53,7 +53,6 @@ class PDFView extends StatefulWidget { final ErrorCallback? onError; final PageErrorCallback? onPageError; final LinkHandlerCallback? onLinkHandler; - final bool useHybridComposition; /// Which gestures should be consumed by the pdf view. /// @@ -84,38 +83,24 @@ class PDFView extends StatefulWidget { } class _PDFViewState extends State { - final Completer _controller = Completer(); + final Completer _controller = + 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 ?? const >{}, + gestureRecognizers: widget.gestureRecognizers ?? + const >{}, hitTestBehavior: PlatformViewHitTestBehavior.opaque, ); }, onCreatePlatformView: (PlatformViewCreationParams params) { - if (widget.useHybridComposition) { - return PlatformViewsService.initExpensiveAndroidView( - id: params.id, - viewType: 'plugins.endigo.io/pdfview', - layoutDirection: TextDirection.rtl, - creationParams: _CreationParams.fromWidget(widget).toMap(), - creationParamsCodec: const StandardMessageCodec(), - ) - ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated) - ..addOnPlatformViewCreatedListener((int id) { - _onPlatformViewCreated(id); - }) - ..create(); - } return PlatformViewsService.initSurfaceAndroidView( id: params.id, viewType: 'plugins.endigo.io/pdfview', @@ -123,8 +108,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(); @@ -139,7 +125,8 @@ class _PDFViewState extends State { creationParamsCodec: const StandardMessageCodec(), ); } - return Text('$defaultTargetPlatform is not yet supported by the pdfview_flutter plugin'); + return Text( + '$defaultTargetPlatform is not yet supported by the pdfview_flutter plugin'); } void _onPlatformViewCreated(int id) { @@ -153,7 +140,8 @@ class _PDFViewState extends State { @override void didUpdateWidget(PDFView oldWidget) { super.didUpdateWidget(oldWidget); - _controller.future.then((PDFViewController controller) => controller._updateWidget(widget)); + _controller.future.then( + (PDFViewController controller) => controller._updateWidget(widget)); } } @@ -190,18 +178,17 @@ 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}); static _PDFViewSettings fromWidget(PDFView widget) { return _PDFViewSettings( @@ -264,10 +251,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); } @@ -288,7 +274,8 @@ class PDFViewController { return null; case 'onPageChanged': if (_widget.onPageChanged != null) { - _widget.onPageChanged!(call.arguments['page'], call.arguments['total']); + _widget.onPageChanged!( + call.arguments['page'], call.arguments['total']); } return null; @@ -311,7 +298,8 @@ class PDFViewController { return null; } - throw MissingPluginException('${call.method} was invoked but has no handler'); + throw MissingPluginException( + '${call.method} was invoked but has no handler'); } Future getPageCount() async { @@ -325,7 +313,8 @@ class PDFViewController { } Future setPage(int page) async { - final bool? isSet = await _channel.invokeMethod('setPage', { + final bool? isSet = + await _channel.invokeMethod('setPage', { 'page': page, }); return isSet;