initVolvoxGrid function

Future<void> initVolvoxGrid({
  1. String? libraryName,
})

Implementation

Future<void> initVolvoxGrid({String? libraryName}) {
  final raw = libraryName?.trim();
  final hasRaw = raw != null && raw.isNotEmpty;

  if (Platform.isIOS && !hasRaw) {
    _transport = _NativeVolvoxGridTransport.open(
      const _NativeLibrarySpec.process(),
    );
    return Future<void>.value();
  }

  final treatAsPath = hasRaw && _looksLikeLibraryPath(raw);
  final effectivePath = treatAsPath ? raw : _defaultLibraryFileName();
  final candidates = treatAsPath
      ? <String>[effectivePath]
      : _candidateLibraryPaths(effectivePath).toList(growable: false);

  Object? lastError;
  StackTrace? lastStackTrace;
  for (final candidate in candidates) {
    try {
      synurang.registerPlugin(candidate, ['VolvoxGridService']);
      _transport = _synurangTransport;
      return Future<void>.value();
    } catch (error, stackTrace) {
      lastError = error;
      lastStackTrace = stackTrace;
    }
  }

  if (lastError != null) {
    Error.throwWithStackTrace(lastError, lastStackTrace ?? StackTrace.current);
  }
  return Future<void>.value();
}