Skip to content

Commit

Permalink
Revert "refactor: add initExpensiveAndroidView"
Browse files Browse the repository at this point in the history
This reverts commit 86f0f00.
  • Loading branch information
LocLt-Mobile committed Dec 25, 2023
1 parent c44ed33 commit 15f8fef
Showing 1 changed file with 36 additions and 47 deletions.
83 changes: 36 additions & 47 deletions lib/flutter_pdfview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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.
///
Expand Down Expand Up @@ -84,47 +83,34 @@ class PDFView extends StatefulWidget {
}

class _PDFViewState extends State<PDFView> {
final Completer<PDFViewController> _controller = Completer<PDFViewController>();
final Completer<PDFViewController> _controller =
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 ?? const <Factory<OneSequenceGestureRecognizer>>{},
gestureRecognizers: widget.gestureRecognizers ??
const <Factory<OneSequenceGestureRecognizer>>{},
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',
layoutDirection: TextDirection.rtl,
creationParams: _CreationParams.fromWidget(widget).toMap(),
creationParamsCodec: const StandardMessageCodec(),
)
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
..addOnPlatformViewCreatedListener((int id) {
..addOnPlatformViewCreatedListener(params
.onPlatformViewCreated)..addOnPlatformViewCreatedListener((
int id) {
_onPlatformViewCreated(id);
})
..create();
Expand All @@ -139,7 +125,8 @@ class _PDFViewState extends State<PDFView> {
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) {
Expand All @@ -153,7 +140,8 @@ class _PDFViewState extends State<PDFView> {
@override
void didUpdateWidget(PDFView oldWidget) {
super.didUpdateWidget(oldWidget);
_controller.future.then((PDFViewController controller) => controller._updateWidget(widget));
_controller.future.then(
(PDFViewController controller) => controller._updateWidget(widget));
}
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand All @@ -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<int?> getPageCount() async {
Expand All @@ -325,7 +313,8 @@ class PDFViewController {
}

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

0 comments on commit 15f8fef

Please sign in to comment.