pdfrxFlutterInitialize function

Future<void> pdfrxFlutterInitialize({
  1. @Deprecated('WASM modules are now only included in web builds. This flag now does nothing.') bool dismissPdfiumWasmWarnings = false,
  2. bool processWidePdfiumGate = false,
})

Explicitly initializes the Pdfrx library for Flutter.

This function actually sets up the following functions:

Set processWidePdfiumGate on every Flutter engine before initialization when using desktop_multi_window. See Pdfrx.useProcessWidePdfiumGate.

For Dart (non-Flutter) programs, you should call pdfrxInitialize instead.

Implementation

Future<void> pdfrxFlutterInitialize({
  @Deprecated('WASM modules are now only included in web builds. This flag now does nothing.')
  bool dismissPdfiumWasmWarnings = false,

  /// See [Pdfrx.useProcessWidePdfiumGate].
  bool processWidePdfiumGate = false,
}) async {
  if (processWidePdfiumGate) {
    Pdfrx.useProcessWidePdfiumGate = true;
  }
  if (_isInitialized) return;

  WidgetsFlutterBinding.ensureInitialized();

  if (pdfrxEntryFunctionsOverride != null) {
    PdfrxEntryFunctions.instance = pdfrxEntryFunctionsOverride!;
  }

  Pdfrx.loadAsset ??= (name) async {
    final asset = await rootBundle.load(name);
    return asset.buffer.asUint8List();
  };

  if (!kIsWeb) {
    Pdfrx.cacheDirectoryPath ??= await getCacheDirectory();
  }

  /// NOTE: it's actually async, but hopefully, it finishes quickly...
  await platformInitialize();

  _isInitialized = true;
}