Flutter AI Chat

A modern, cross-platform AI chat interface built with Flutter that supports streaming responses and conversation management.

Flutter AI Chat Example

Features

  • ๐Ÿค– AI Chat Interface - Chat with AI models using OpenAI API
  • ๐Ÿ“ฑ Cross-Platform Support - Works on iOS, Android, Web, Windows, macOS, and Linux
  • ๐ŸŒŠ Streaming Responses - Real-time AI responses with streaming support
  • ๐Ÿ’ฌ Conversation Management - Create, manage, and organize chat conversations
  • ๐ŸŽจ Modern UI/UX - Beautiful Material Design 3 interface with light/dark themes
  • ๐Ÿ“ฑ Responsive Design - Adapts to different screen sizes and orientations
  • ๐Ÿ”’ Secure - Secure API key management and data handling
  • โšก Web Optimized - Optimized web build with CanvasKit renderer for better performance
  • ๐Ÿงช High Quality - Analyzed with Pana, Flutter analyze, and Dart analysis

Preview

Flutter AI Chat Example Preview

Platform Support

Platform Status Notes
iOS โœ… Supported iPhone and iPad
Android โœ… Supported Phone and Tablet
Web โœ… Supported Chrome, Firefox, Safari, Edge
Windows โœ… Supported Desktop
macOS โœ… Supported Desktop
Linux โœ… Supported Desktop

Getting Started

Prerequisites

  • Flutter SDK: >=3.32.0
  • Dart SDK: >=3.8.0
  • OpenAI API Key (for AI functionality)

Installation

  1. Clone the repository:
git clone https://github.com/Dhia-Bechattaoui/flutter_ai_chat.git
cd flutter_ai_chat
  1. Install dependencies:
flutter pub get
  1. Configure your OpenAI API key:

    • Create a .env file in the root directory (for package-level usage)
    • Add your API key: OPENAI_API_KEY=your_api_key_here
    • For the example app, place the .env inside example/.env
  2. Run the example app (recommended to see all features):

cd example
flutter run
  1. Use the package in your app:
dependencies:
  flutter_ai_chat: ^0.1.0

Web Deployment

For web deployment with optimized rendering:

flutter build web --web-renderer canvaskit

This uses CanvasKit renderer for better performance and consistency across browsers.

Configuration

Environment Variables

Create a .env file in the root directory:

OPENAI_API_KEY=your_openai_api_key_here

For the example app, place the file at example/.env with the same key.

API Configuration

The app is configured to use OpenAI's GPT models by default. You can modify the configuration in lib/services/ai_service.dart (model, base URL, timeouts, headers).

Architecture

The project follows a clean architecture pattern with the following structure:

lib/
โ”œโ”€โ”€ flutter_ai_chat.dart     # Package exports
โ”œโ”€โ”€ models/                   # Data models
โ”‚   โ”œโ”€โ”€ chat_message.dart    # Chat message model
โ”‚   โ””โ”€โ”€ conversation.dart    # Conversation model
โ”œโ”€โ”€ providers/               # State management
โ”‚   โ””โ”€โ”€ chat_provider.dart  # Chat state provider
โ”œโ”€โ”€ screens/                 # UI screens
โ”‚   โ””โ”€โ”€ chat_screen.dart    # Main chat interface
โ”œโ”€โ”€ services/                # Business logic
โ”‚   โ””โ”€โ”€ ai_service.dart     # AI API service
โ”œโ”€โ”€ utils/                   # Utilities
โ”‚   โ””โ”€โ”€ theme.dart          # App theme configuration
โ””โ”€โ”€ widgets/                 # Reusable widgets
    โ”œโ”€โ”€ chat_input_widget.dart
    โ”œโ”€โ”€ chat_message_widget.dart
    โ””โ”€โ”€ sidebar_widget.dart

Dependencies

Core Dependencies

  • flutter - Flutter SDK
  • provider - State management
  • http - HTTP client for API calls
  • dio - HTTP client (used for streaming responses)
  • shared_preferences / sqflite - Local storage
  • flutter_markdown_plus - Markdown rendering for AI responses
  • flutter_dotenv - Environment variable management

Development Dependencies

  • flutter_lints - Code quality rules
  • flutter_test - Testing framework
  • mockito - Mocking for tests
  • dartdoc - Documentation generation

Quality Assurance

This project maintains high code quality standards:

  • โœ… Pana Analysis - Full score compliance
  • โœ… Flutter Analyze - No analysis issues
  • โœ… Dart Analysis - Clean code standards
  • โœ… Linting - Strict linting rules
  • โœ… Testing - Comprehensive test coverage including unit tests for services, models, and providers

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Testing

Run the test suite:

flutter test

Run with coverage:

flutter test --coverage

Building for Production

Android

flutter build apk --release

iOS

flutter build ios --release

Web

flutter build web --release --web-renderer canvaskit

Desktop

flutter build windows --release
flutter build macos --release
flutter build linux --release

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Flutter team for the amazing framework
  • OpenAI for providing the AI API
  • Material Design team for the design system
  • All contributors and supporters

Support

If you encounter any issues or have questions:

  1. Check the Issues page
  2. Create a new issue with detailed information
  3. Contact the maintainer: Dhia-Bechattaoui

Roadmap

  • Voice input support
  • Image generation integration
  • Multi-language support
  • Offline mode
  • Advanced conversation analytics
  • Plugin system for custom AI providers

Made with โค๏ธ using Flutter