initImpl method

  1. @protected
Future<void> initImpl({
  1. RustLibApi? api,
  2. BaseHandler? handler,
  3. ExternalLibrary? externalLibrary,
})
inherited

This is only intended to be used by automatically generated code, instead of developers.

Implementation

@protected
Future<void> initImpl({
  A? api,
  BaseHandler? handler,
  ExternalLibrary? externalLibrary,
}) async {
  if (__state != null) {
    throw StateError('Should not initialize flutter_rust_bridge twice');
  }

  if (codegenVersion != kFlutterRustBridgeRuntimeVersion) {
    throw StateError(
      "flutter_rust_bridge's codegen version ($codegenVersion) should be the same as runtime version ($kFlutterRustBridgeRuntimeVersion). "
      "See https://cjycode.com/flutter_rust_bridge/guides/miscellaneous/upgrade/regular for details.",
    );
  }

  externalLibrary ??= await _loadDefaultExternalLibrary();
  handler ??= BaseHandler();
  final generalizedFrbRustBinding =
      GeneralizedFrbRustBinding(externalLibrary);
  final portManager = PortManager(generalizedFrbRustBinding, handler);
  api ??= _createDefaultApi(
      handler, generalizedFrbRustBinding, portManager, externalLibrary);

  __state = _EntrypointState(
    generalizedFrbRustBinding: generalizedFrbRustBinding,
    portManager: portManager,
    api: api,
  );

  await executeRustInitializers();
}