Skip to content

Commit

Permalink
add use HybridComposition and fix issue display incorrect on samsung …
Browse files Browse the repository at this point in the history
…android 14
  • Loading branch information
LocLt-Mobile committed Dec 25, 2023
1 parent 7cacf1d commit 9d4ca90
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 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.useHybridComposition = false,
}) : assert(filePath != null || pdfData != null),
super(key: key);

@override
Expand All @@ -53,6 +53,7 @@ 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 @@ -83,24 +84,39 @@ 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',
Expand Down

0 comments on commit 9d4ca90

Please sign in to comment.