Skip to content

Repository files navigation

AI Chat Flutter Project

<<<<<<< HEAD A Flutter-based chat application with AI integration.

Getting Started: Your First Steps

======= A feature-rich Flutter-based chat application with AI integration, user-to-user messaging, and Firebase backend support. This app demonstrates modern Flutter development practices including Riverpod state management, clean architecture, and Firebase integration.

✨ Features

  • πŸ€– AI Chat - Chat with AI powered by OpenRouter LLM
  • πŸ‘₯ User-to-User Chat - Real-time messaging between users
  • πŸ” Authentication - Google Sign-In and OTP-based authentication with Firebase
  • πŸ”” Push Notifications - Real-time notifications via Firebase Cloud Messaging
  • 🌍 Multi-Language Support - English, Khmer, Japanese, and Spanish
  • 🎨 Theme Support - Light and dark theme modes
  • πŸ“± Responsive Design - Works seamlessly on Android and iOS
  • πŸ’Ύ Local Storage - Task management with local persistence using Hive

πŸ›  Tech Stack

  • Framework: Flutter 3.x
  • State Management: Riverpod
  • Backend: Firebase (Authentication, Firestore, Cloud Messaging)
  • API Client: Dio
  • Local Database: Hive
  • LLM Integration: OpenRouter API
  • Code Generation: Freezed, JsonSerializable

πŸ“‹ Prerequisites

Before you begin, ensure you have:

Verify Installation

flutter --version
dart --version

πŸš€ Getting Started: Your First Steps

7d9fef6f29f2a57f4f5db38905d5c8924ec4ab30

This guide will walk you through setting up and running the project. Follow these steps carefully, and you'll have the app running in no time!

1. Clone the Repository

First, get the project files onto your computer.

git clone <repository-url>
cd <repository-directory>

2. Clean Up & Get Dependencies

It's always a good idea to start with a clean slate and fetch all necessary packages.

flutter clean
flutter pub get

3. Set Up Firebase: The Backend Power

This project uses Firebase for authentication, database, and other services. You'll need to connect your app to your own Firebase project.

3.1. Create Your Firebase Project

  1. Go to the Firebase console.
  2. Click "Add project" and follow the on-screen instructions to create a new project.

3.2. Connect Your Android App to Firebase

This is crucial for features like Google Sign-In and push notifications.

  1. Add an Android App: In your Firebase project, click the Android icon to add a new Android app.

    • Package Name: Enter your app's package name. You can find this in android/app/build.gradle.kts (look for applicationId).
  2. Get Your SHA-1 and SHA-256 Keys: These keys are essential for Google Sign-In and other Firebase services to verify your app's authenticity.

    • For Windows: Open your terminal and run this command:

      keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
    • For macOS and Linux: Open your terminal and run this command:

      keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
    • After running the command, copy both the SHA1 and SHA256 fingerprints from the output.

  3. Add SHA Keys to Firebase: In your Firebase project settings, select your Android app, then click "Add fingerprint" and paste your copied SHA-1 and SHA256 keys.

  4. Download google-services.json: Download the google-services.json file from the Firebase console.

  5. Place google-services.json: Move this downloaded file into the android/app directory of your Flutter project.

3.3. Connect Your iOS App to Firebase (Optional, if targeting iOS)

  1. Add an iOS App: In your Firebase project, click the iOS icon to add a new iOS app.
  2. Download GoogleService-Info.plist: Download the GoogleService-Info.plist file from the Firebase console.
  3. Place GoogleService-Info.plist: Move this file into the ios/Runner directory of your Flutter project.

3.4. Deploy Firestore Rules (If you modify them)

If you make changes to your Firestore security rules (firestore.rules), you'll need to deploy them.

firebase deploy --only firestore:rules --project <your-firebase-project-id>

Replace <your-firebase-project-id> with your actual Firebase project ID.

<<<<<<< HEAD

4. Add AI Provider API Key

The application uses Custom LLM via OpenRouter for its AI chat features. For detailed steps on how to obtain your API key, refer to How to Get Your OpenRouter AI API Key.

  1. Create a file named .env in the root of the project.

  2. Add your OpenRouter API key to the .env file as follows:

    AI_API_KEY='your_api_key_here'
    

=======

4. Configure Environment Variables

This project requires several API keys and configuration values. These are stored in a .env file which is not included in the repository for security reasons.

4.1. Create Your .env File

  1. Copy the example file to create your own:

    cp .env.example .env
  2. Edit the .env file and replace all placeholder values with your actual credentials:

    # LLM Configuration (Required for AI features)
    AI_API_KEY=your_actual_api_key_here
    CUSTOM_LLM_ENDPOINT=https://your-custom-llm-endpoint.com/api/v1/chat/completions
    CUSTOM_LLM_model=your_model_name
    BASE_API_URL=https://your-backend-api-url.com
    
    # Firebase Configuration (Required)
    FIREBASE_PROJECT_ID=your_firebase_project_id
    FIREBASE_API_KEY=your_firebase_api_key
    FIREBASE_APP_ID=your_firebase_app_id
    FIREBASE_MESSAGING_SENDER_ID=your_firebase_sender_id
    FIREBASE_STORAGE_BUCKET=your_firebase_storage_bucket
    FIREBASE_ANDROID_CLIENT_ID=your_android_client_id
    FIREBASE_IOS_CLIENT_ID=your_ios_client_id
    FIREBASE_IOS_BUNDLE_ID=your_ios_bundle_id

4.2. Get Your API Keys

  • AI_API_KEY & CUSTOM_LLM Settings: For OpenRouter LLM integration, see How to Get Your OpenRouter AI API Key
  • Firebase Configuration: Get these from your Firebase project settings
  • Backend API URL: Use your own backend API endpoint (or a development server URL)

7d9fef6f29f2a57f4f5db38905d5c8924ec4ab30

5. Generate Code (Build Runner)

This project uses code generation. You need to run the build runner to generate necessary files.

flutter run build_runner

6. Run the Application

Finally, launch the application!

flutter run

<<<<<<< HEAD

πŸ“ Project Structure

lib/
β”œβ”€β”€ app.dart                 # Main app configuration
β”œβ”€β”€ main.dart                # Entry point
β”œβ”€β”€ firebase_options.dart    # Firebase configuration
β”œβ”€β”€ core/
β”‚   β”œβ”€β”€ api/                 # API client setup (Dio)
β”‚   β”œβ”€β”€ config/              # Environment configuration
β”‚   β”œβ”€β”€ services/            # Services (Firebase, Sound, etc.)
β”‚   β”œβ”€β”€ utils/               # Utility functions
β”‚   β”œβ”€β”€ widgets/             # Reusable widgets
β”‚   └── errors/              # Error handling
β”œβ”€β”€ features/
β”‚   β”œβ”€β”€ ai_chat/             # AI Chat feature
β”‚   β”œβ”€β”€ utou_chat/           # User-to-User Chat feature
β”‚   β”œβ”€β”€ auth/                # Authentication feature
β”‚   β”œβ”€β”€ home/                # Home/Dashboard feature
β”‚   β”œβ”€β”€ tasks/               # Task management feature
β”‚   β”œβ”€β”€ app_settings/        # App settings & preferences
β”‚   └── user/                # User profile feature
β”œβ”€β”€ l10n/                    # Localization files
└── app/
    β”œβ”€β”€ router.dart          # Route configuration
    └── theme/               # Theme configuration

πŸ”§ Troubleshooting

Build Issues

MissingPluginException

Problem: Plugin not initialized
Solution: Run flutter clean and flutter pub get

Firebase Configuration Error

Problem: google-services.json not found
Solution: Ensure google-services.json is placed in android/app/ directory

Build Cache Issues

Problem: Strange compilation errors
Solution: Clean everything:

flutter clean
rm -rf pubspec.lock
flutter pub get

Runtime Errors

Invalid BASE_API_URL

Problem: BaseUrl must be a valid URL
Solution: Check .env file has a valid BASE_API_URL value

FocusNode Disposed Error

Problem: FocusScopeNode already disposed
Solution: Update to the latest version of the app (we've fixed this)

Firebase Issues

  • No notifications? Ensure Firebase Cloud Messaging is enabled in your Firebase Console
  • Auth not working? Check SHA-1 and SHA-256 keys are correctly added to Firebase
  • Firestore errors? Verify firestore rules are deployed: firebase deploy --only firestore:rules

πŸ“š Documentation

For more detailed information, check out our documentation:

🀝 Contributing

Contributions are welcome! To contribute:

  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

Please ensure your code follows the Best Practices guide.

πŸ“ License

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

πŸ“§ Support

For issues, feature requests, or questions:

πŸ™ Acknowledgments

  • Flutter team for the amazing framework
  • Firebase for backend services
  • OpenRouter for LLM integration
  • All our contributors and supporters

Happy Coding! πŸš€

7d9fef6f29f2a57f4f5db38905d5c8924ec4ab30

About

An ideal Flutter starter kit designed for building AI chat applications, task management systems, and intelligent AI agents.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages