Flutter AI Toolkit provides chat widgets around a provider interface. Start with a minimal text conversation, verify its states and then choose whether your product needs history, attachments or custom response widgets.
Prepare a local Firebase-enabled project
Create a disposable learning project and add flutter_ai_toolkit, firebase_ai and firebase_core. Review the compatible versions in the
AI Toolkit integration guide
; use the resolved lockfile in your own app rather than copying a random package combination.
flutter pub add flutter_ai_toolkit firebase_ai firebase_core
Enable the intended Firebase AI Logic provider in a Firebase project. Register the platforms you will run, install/configure the FlutterFire CLI according to your environment and run flutterfire configure. That generates your project’s firebase_options.dart. Configuration may involve service quotas or billing; inspect the selected project before running real requests.
Wire a minimal screen
The following local lib/main.dart expects the generated options file. Select a model available for your provider using a build-time name; the example intentionally does not pin a model that may become unavailable.
import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart';
import 'firebase_options.dart';
const modelName = String.fromEnvironment('AI_MODEL');
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
if (modelName.isEmpty) {
throw StateError('Choose an available model with --dart-define=AI_MODEL=...');
}
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
final provider = FirebaseProvider(
model: FirebaseAI.googleAI().generativeModel(model: modelName),
);
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Lesson assistant')),
body: LlmChatView(provider: provider),
),
));
}
Run with your actual enabled model: flutter run --dart-define=AI_MODEL=YOUR_ENABLED_MODEL. This is not a DartPad example: Firebase configuration, compatible dependencies and a real provider connection are required.
Understand each responsibility
Firebase initialization chooses the app configuration. FirebaseAI selects the provider endpoint and model. FirebaseProvider adapts that model to the toolkit, while LlmChatView supplies the conversation interface. The provider is created once in this example rather than on every chat-screen rebuild.
This snippet uses the Google AI endpoint. A different enabled endpoint needs the corresponding provider configuration. A build-time model name is configuration, not a secret store; browser and mobile binaries can be inspected. Keep privileged server credentials off the client and review Firebase App Check and quota controls before public use.
Verify before adding features
Send a short prompt and inspect response streaming. Then test a disconnected network, a rejected or unsupported model, an empty prompt and repeated navigation. Confirm that failures give the user a recoverable state. Use a provider fake for ordinary UI tests so a random model response is not part of every test run.
Exercise
Add a visible explanation of what the assistant can help with and one application-specific validation rule. Use AI quality checks to verify behavior. A working chat demo still needs product-specific privacy, cost and reliability decisions before launch.