initialize static method

Future<void> initialize({
  1. String? huggingFaceToken,
  2. int maxDownloadRetries = 10,
  3. bool enableWebCache = true,
})

Initialize Flutter Gemma

Call this once at app startup before using any other API.

Parameters:

  • huggingFaceToken: Optional HuggingFace API token for authenticated downloads
  • maxDownloadRetries: Maximum retry attempts for transient errors (default: 10) Note: Auth errors (401/403/404) always fail after 1 attempt
  • enableWebCache: Enable persistent caching on web platform (default: true) Note: This parameter only affects web platform, ignored on mobile

Example:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await FlutterGemma.initialize();
  runApp(MyApp());
}

Implementation

static Future<void> initialize({
  String? huggingFaceToken,
  int maxDownloadRetries = 10,
  bool enableWebCache = true,
}) async {
  ServiceRegistry.initialize(
    huggingFaceToken: huggingFaceToken,
    maxDownloadRetries: maxDownloadRetries,
    enableWebCache: enableWebCache,
  );
}