flutter_native_ai 0.1.0 copy "flutter_native_ai: ^0.1.0" to clipboard
flutter_native_ai: ^0.1.0 copied to clipboard

A Flutter plugin for native on-device generative AI through Apple Foundation Models and Android Gemini Nano.

flutter_native_ai #

A Flutter plugin for private, on-device text generation using native platform AI models. It gives Flutter apps one small Dart API over Apple Foundation Models on Apple platforms and Gemini Nano through ML Kit Prompt API / AICore on Android.

The package exposes one Dart API for checking availability, initializing a local model session, generating a complete response, and streaming cumulative text updates.

Platform Support #

Platform Minimum app target Native model requirement Runtime behavior
iOS iOS 13.0 Apple Foundation Models on supported OS/device combinations Installs on older iOS versions; availability() returns unavailable when Foundation Models are not present
macOS Not implemented yet Apple Foundation Models on supported OS/device combinations Planned; currently unsupported
Android minSdk 26 Gemini Nano through ML Kit Prompt API / AICore on supported devices Installs on Android 8.0+; availability() returns unavailable unless the native model is available
Other platforms Not supported None Returns unsupported availability

This package does not send prompts or generated text to a server. Generation is performed by native on-device model APIs when those APIs are available.

Use Case #

The package was extracted from Pooka, where it powers short private collection insights without sending collection data to a backend model.

Installation #

dependencies:
  flutter_native_ai: ^0.1.0-alpha.1

Usage #

import 'package:flutter_native_ai/flutter_native_ai.dart';

final ai = OnDeviceAi();

final availability = await ai.availability();
if (!availability.isAvailable) {
  print(availability.reason);
  return;
}

await ai.initialize(
  instructions: 'You are a concise assistant. Keep answers practical.',
);

final result = await ai.generateText(
  prompt: 'Write one sentence about on-device AI.',
  config: const OnDeviceAiGenerationConfig(
    maxTokens: 80,
    temperature: 0.4,
  ),
);

print(result.text);

Streaming:

await for (final chunk in ai.generateTextStream(
  prompt: 'Summarize this in two short sentences.',
)) {
  print(chunk.text);
}

Stream chunks are cumulative snapshots. If the model emits "Hello" and then "Hello world", the stream emits both snapshots rather than only the delta.

Availability #

Always call availability() before initializing or generating text. Native model availability depends on the OS, device, regional/account settings, and whether the local model is present.

The minimum app target only describes where the plugin can be installed. It does not guarantee that native AI is available. For example, iOS versions below the Foundation Models runtime still work as app targets, but this package reports the model as unavailable.

Android currently reports downloadable and downloading states as unavailable. The package does not start model downloads automatically.

API #

Main entry point:

  • OnDeviceAi

Models:

  • OnDeviceAiAvailability
  • OnDeviceAiGenerationConfig
  • OnDeviceAiGenerationResult
  • OnDeviceAiStreamChunk

Methods:

  • availability()
  • initialize({String? instructions})
  • generateText({required String prompt, OnDeviceAiGenerationConfig config})
  • generateTextStream({required String prompt, OnDeviceAiGenerationConfig config})
  • cancelStreamingText()

Regenerating Platform Bindings #

Platform channels are generated with Pigeon from pigeons/on_device_ai.dart.

dart run pigeon --input pigeons/on_device_ai.dart
dart format lib/src/generated/on_device_ai.g.dart pigeons/on_device_ai.dart

Pigeon currently emits open fun modifiers in a generated Kotlin interface. Those are removed in the checked-in generated Kotlin binding because Kotlin interface members are overridable by default.

AI-Assisted Development #

This package was built with AI assistance for parts of the implementation, especially around the Pigeon contract, generated platform-channel integration, and native bridge scaffolding. AI was used as an engineering tool in a deliberate implementation process; the package is not vibe-coded.

Notes #

This package is an early alpha. Apple Foundation Models and Gemini Nano APIs are new and may change. The Dart API is intentionally small so platform-specific changes can be handled behind the plugin boundary.

3
likes
0
points
639
downloads

Publisher

verified publisherpooka.app

Weekly Downloads

A Flutter plugin for native on-device generative AI through Apple Foundation Models and Android Gemini Nano.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, meta

More

Packages that depend on flutter_native_ai

Packages that implement flutter_native_ai