ai_assistant_ui 0.0.2 copy "ai_assistant_ui: ^0.0.2" to clipboard
ai_assistant_ui: ^0.0.2 copied to clipboard

A customizable, modern AI Chat UI library for Flutter supporting Google Gemini, OpenAI, Claude, Ollama, dynamic light/dark themes, and chat history persistence.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:ai_assistant_ui/ai_assistant_ui.dart';

void main() {
  runApp(const DemoApp());
}

class DemoApp extends StatefulWidget {
  const DemoApp({super.key});

  @override
  State<DemoApp> createState() => _DemoAppState();
}

class _DemoAppState extends State<DemoApp> {
  ThemeMode _themeMode = ThemeMode.dark;
  String _selectedProvider = 'gemini';

  void _toggleTheme() {
    setState(() {
      _themeMode =
          _themeMode == ThemeMode.dark ? ThemeMode.light : ThemeMode.dark;
    });
  }

  AIProvider _getProvider() {
    switch (_selectedProvider) {
      case 'openai':
        return OpenAIProvider(
          apiKey: 'YOUR_OPENAI_KEY',
          model: 'gpt-4o-mini',
        );
      case 'claude':
        return ClaudeProvider(
          apiKey: 'YOUR_CLAUDE_KEY',
          model: 'claude-3-5-sonnet-20240620',
        );
      case 'ollama':
        return OllamaProvider(
          baseUrl: 'http://localhost:11434',
          model: 'llama3',
        );
      case 'custom':
        return CustomProvider(
          providerId: 'custom-demo',
          displayName: 'Mock AI Backend',
          streamHandler: (history, prompt, attachments, cancelToken) async* {
            yield 'Hello! This is a demo stream from a **Custom Backend**.\n\n';
            await Future.delayed(const Duration(milliseconds: 500));
            yield 'You asked: "$prompt". Everything is working smoothly!';
          },
        );
      case 'gemini':
      default:
        return GeminiProvider(
          apiKey: 'YOUR_GEMINI_KEY',
          model: 'gemini-1.5-flash',
        );
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AravGPT Showcase Demo',
      debugShowCheckedModeBanner: false,
      themeMode: _themeMode,
      theme: ThemeData.light(useMaterial3: true),
      darkTheme: ThemeData.dark(useMaterial3: true),
      home: Scaffold(
        body: AIChatView(
          provider: _getProvider(),
          config: AIChatConfig(
            title: 'AravGPT (${_selectedProvider.toUpperCase()})',
            placeholderText: 'Ask anything...',
            welcomeMessage: 'How can I help you today?',
            enableHistoryDrawer: true,
            enableMarkdown: true,
          ),
          isDarkMode: _themeMode == ThemeMode.dark,
          onThemeToggle: _toggleTheme,
          storage: HiveChatStorage(),
        ),
      ),
    );
  }
}
2
likes
140
points
117
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A customizable, modern AI Chat UI library for Flutter supporting Google Gemini, OpenAI, Claude, Ollama, dynamic light/dark themes, and chat history persistence.

Repository (GitHub)
View/report issues

Topics

#flutter #ai #chatbot #gemini #openai

License

MIT (license)

Dependencies

dio, equatable, flutter, flutter_bloc, flutter_markdown, hive, hive_flutter

More

Packages that depend on ai_assistant_ui