Skip to content

Commit 3bf1f38

Browse files
committed
Moved an external setup call to an initializer.
1 parent c77a98e commit 3bf1f38

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

example/lib/main.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
282282

283283
@override
284284
Widget build(BuildContext context) {
285-
Pspdfkit.setupPlatformCallHandler();
286285
Pspdfkit.flutterPdfActivityOnPause = () => flutterPdfActivityOnPauseHandler();
287286
Pspdfkit.pdfViewControllerWillDismiss = () => pdfViewControllerWillDismissHandler();
288287
Pspdfkit.pdfViewControllerDidDismiss = () => pdfViewControllerDidDismissHandler();

lib/pspdfkit.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ part 'configuration_options.dart';
1818

1919
/// PSPDFKit plugin to load PDF and image documents on both platform iOS and Android.
2020
class Pspdfkit {
21-
static const MethodChannel _channel = const MethodChannel('pspdfkit');
21+
static MethodChannel _privateChannel = null;
22+
23+
static MethodChannel get _channel {
24+
if (_privateChannel == null) {
25+
_privateChannel = const MethodChannel('pspdfkit');
26+
_privateChannel.setMethodCallHandler(_platformCallHandler);
27+
}
28+
return _privateChannel;
29+
}
2230

2331
/// Gets the PSPDFKit framework version.
2432
static Future<String> get frameworkVersion async =>
@@ -119,8 +127,4 @@ class Pspdfkit {
119127
}
120128
return Future.value();
121129
}
122-
123-
static void setupPlatformCallHandler() {
124-
_channel.setMethodCallHandler(_platformCallHandler);
125-
}
126130
}

0 commit comments

Comments
 (0)