createFlutterDeps function

LexioLabDeps createFlutterDeps({
  1. LLStorageMode storage = LLStorageMode.auto,
  2. Client? httpClient,
  3. DateTime now()?,
  4. Directory? storageDirectory,
  5. void warn(
    1. String message
    )?,
})

Builds the real dependencies.

storageDirectory is resolved LAZILY, on the first cache access, so constructing a client never awaits a platform channel and the first frame never waits for the disk.

Implementation

LexioLabDeps createFlutterDeps({
  LLStorageMode storage = LLStorageMode.auto,
  http.Client? httpClient,
  DateTime Function()? now,
  Directory? storageDirectory,
  void Function(String message)? warn,
}) {
  final http.Client client = httpClient ?? http.Client();
  return LexioLabDeps(
    fetch: _httpFetch(client),
    storage: switch (storage) {
      LLStorageMode.off => const LLNullStorage(),
      LLStorageMode.memory => LLMemoryStorage(),
      LLStorageMode.auto => LLLazyFileStorage(storageDirectory),
    },
    now: now ?? DateTime.now,
    hash: sha256Hash,
    // A microtask, not a post-frame callback: the core's boot must not wait for
    // a frame that a headless test will never produce.
    defer: scheduleMicrotaskDefer,
    warn: warn ?? _defaultWarn,
  );
}