FlutterAdvanced 3 min read

Flutter AI architecture: Genkit agents and on-device models

Choose between server-side agent flows and local inference, then define a testable client boundary.

On this page

AI deployment is an architecture choice. A server-side agent can coordinate tools and providers, while an on-device model can perform supported inference without a cloud round trip. Choose from the feature’s data, device and reliability needs.

Separate three layers

Flutter owns input, progress and results. An application service owns authentication and the operation contract. The inference or agent layer owns the selected model and any supported tools. Keep these roles visible even in a small prototype.

Genkit provides agentic application tooling with Dart support, including typed flows, streaming and tool integration. Begin from its Dart quick-start entry when creating the agent service. Its runtime and provider setup are separate from the static tutorial website’s hosting.

The MediaPipe Flutter gallery demonstrates supported on-device task packages. Device support, model assets and platform configuration must be checked for the chosen task. “On-device” does not mean every model runs in every browser or on every phone.

Design the operation before choosing a package

For a lesson recommender, define a request containing the current topic and an allowed list of lesson IDs. Return a bounded list of IDs plus an explanation. The Flutter UI resolves those IDs through its own catalog. This makes a fake service possible and prevents a model from inventing navigation destinations.

For a camera-based classification feature, identify where frames are captured, how often inference runs and when the camera/model resources are released. Request platform permissions only for the feature the user chooses to open.

A server-agent development sequence

  1. Create a separate local service project from the current Genkit Dart setup.
  2. Add one provider and verify a plain text response.
  3. Define an input/output schema for a single flow.
  4. Add one read-only tool with validated arguments.
  5. Expose an authenticated application endpoint and connect Flutter through an interface.
  6. Verify timeout, invalid data and unavailable-tool behavior before adding more steps.

Do not put a privileged model-provider key into a browser build or a downloadable mobile binary. A user-facing tool action still needs the service’s usual authorization checks. Confirm an action such as a booking only after validation and a clear user decision.

An on-device development sequence

Select a supported task, include its model asset and verify one known input on the target device. Measure initialization, memory, inference time and battery impact with realistic input sizes. Add a meaningful unavailable-device state instead of silently substituting a cloud upload.

Keep camera and inference lifecycle tests separate from ordinary widget tests. Use fixed task results to exercise the Flutter screen without loading a model in every test run.

Exercise

Compare a server-backed lesson assistant with a local image classifier. Write down the input, where inference runs, model setup, failure states and a verification plan for each. Explain which hosting environment your server process needs; uploading static Flutter web files alone does not start a Genkit service.

How this topic connects

Understand first

Apply it next

Lesson progressMark complete after checking the example and exercise.

Find your next idea

Search lessons, code examples and projects.

Type a few words to start exploring.