ai_chat_kit 0.1.0
ai_chat_kit: ^0.1.0 copied to clipboard
A drop-in AI chat module for Flutter — LLM streaming, voice input, markdown, chat history, typing animation, prompt templates and multi-provider support (OpenAI, Gemini, Claude).
example/lib/main.dart
import 'package:ai_chat_kit/ai_chat_kit.dart';
import 'package:flutter/material.dart';
import 'chat_screen.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// FEATURE 5 — chat history is persisted with Hive; open it once at startup.
await HiveChatStore.init();
runApp(const ExampleApp());
}
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'AI Chat Kit',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorSchemeSeed: const Color(0xFF2E7D32),
useMaterial3: true,
),
home: const HomeScreen(),
);
}
}
/// The seven SDK features this demo exercises (shown to the user up front).
const _features = [
('LLM integration', 'OpenAI-compatible backend via buildService()'),
('Streaming responses', 'Replies render token-by-token'),
('Voice input', 'Tap the mic to dictate'),
('Markdown rendering', 'Answers render as lists, tables and code'),
('Chat history', 'Conversations saved in the drawer'),
('Typing animation', 'Pulse-wave "thinking" indicator'),
('Prompt templates', 'Your service type becomes the assistant\'s role'),
];
/// Quick-fill suggestions for the service-type field. The user can type
/// anything — these are just shortcuts.
const _suggestions = [
'Fitness coach',
'Restaurant concierge',
'Customer support agent',
'Math tutor',
'Travel planner',
'Legal assistant',
];
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
// The free-text service type drives the assistant's behaviour.
final _serviceType = TextEditingController(text: 'Fitness coach');
@override
void dispose() {
_serviceType.dispose();
super.dispose();
}
void _start() {
final type = _serviceType.text.trim();
if (type.isEmpty) return;
Navigator.of(context).push(
MaterialPageRoute<void>(builder: (_) => ChatScreen(serviceType: type)),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(title: const Text('AI Chat Kit')),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
Icon(Icons.smart_toy_outlined,
size: 56, color: theme.colorScheme.primary),
const SizedBox(height: 8),
Text('Build any assistant',
style: theme.textTheme.headlineSmall, textAlign: TextAlign.center),
const SizedBox(height: 20),
// ---- Service type drives the assistant's role ----
Text('What kind of assistant is this?',
style: theme.textTheme.titleMedium),
const SizedBox(height: 8),
TextField(
controller: _serviceType,
textCapitalization: TextCapitalization.sentences,
decoration: const InputDecoration(
hintText: 'e.g. fitness coach, restaurant concierge, tutor…',
helperText: 'The chat behaves as whatever you enter here.',
border: OutlineInputBorder(),
),
onSubmitted: (_) => _start(),
),
const SizedBox(height: 12),
Wrap(
spacing: 8,
children: [
for (final s in _suggestions)
ActionChip(
label: Text(s),
onPressed: () => setState(() {
_serviceType.text = s;
}),
),
],
),
const SizedBox(height: 24),
FilledButton.icon(
icon: const Icon(Icons.chat_bubble_outline),
label: const Text('Start chat'),
onPressed: _start,
),
const SizedBox(height: 28),
Text('Built-in SDK features in this chat:',
style: theme.textTheme.titleMedium),
const SizedBox(height: 8),
Card(
child: Column(
children: [
for (final (title, subtitle) in _features)
ListTile(
dense: true,
leading: const Icon(Icons.check_circle_outline),
title: Text(title),
subtitle: Text(subtitle),
),
],
),
),
],
),
);
}
}