Skip to main content

Command Palette

Search for a command to run...

GemChat ๐Ÿ’Ž

My Gemini-Powered AI Chat App with Flutter, Firebase & BLoC

Published
โ€ข2 min readโ€ขView as Markdown
GemChat ๐Ÿ’Ž

GemChat ๐Ÿ’Ž is a simple yet powerful AI chatbot I built using Flutter, Firebase, and Googleโ€™s Gemini API.

The target was โ€” create a clean, real-time chat experience where every conversation feels fluid, intelligent, and personal.

This article shares how I built GemChat from scratch โ€” from user authentication and conversation storage to AI response handling using the BLoC architecture.

๐Ÿง‘โ€๐Ÿ’ป Source code

๐Ÿ’ก Motivation behind GemChat?

I wanted to combine three things:

  • The intelligence of Gemini (2.5 flash)

  • The reliability of Firebase for managing users & data

  • The structure of BLoC for scalable state management

GemChat merges them into a unified, elegant experience โ€” fast, modular, and easy to extend.

Key Features

โœ… Email + Password Authentication
โœ… Multiple Chat Sessions (via Drawer)
โœ… Auto Scroll to Latest Message
โœ… Retry on Timeout / Error
โœ… Offline Check Before Sending Prompt
โœ… Persistent Chat History in Firestore
โœ… Simple, Beautiful Dark UI

๐Ÿ” Firestore Structure

users/
  userId/
    chats/
      chatId/
        conversations: [
          { prompt: "Hello!", response: "Hi there ๐Ÿ‘‹" },
          { prompt: "What can you do?", response: "I can assist with many things..." }
        ]
        lastUpdated: <timestamp>

Each user can have multiple chat histories, each stored as a list of prompt-response pairs.

๐Ÿง  App Architecture

Firebase Auth
     โ†“
Firestore
     โ†“
ChatBloc (Handles events + states)
     โ†“
ChatRepo (Dio + Gemini API calls)
     โ†“
UI (BlocConsumer + StreamBuilder)

Challenges

  • Handling timeouts gracefully

  • Ensuring auto-scroll after rebuilds

  • Maintaining sync between Firebase and BLoC states

  • Designing Firestore schema for scalability

Lessons Learned

  • Using BLoC for separating UI logic pays off massively.

  • Firestoreโ€™s arrayUnion is perfect for storing structured chat histories.

  • Geminiโ€™s response format requires careful decoding and error handling with Dio.

๐ŸŒฑ Future Enhancements

  • ๐ŸŽ™๏ธ Voice input + speech output

  • ๐Ÿงฉ Markdown & rich text support

  • ๐Ÿช„ Prompt templates (e.g., summarize text, explain code)

  • ๐Ÿง  Gemini 2.5 flash LLM integration for multimodal input

Acknowledgements

Educational resource

Development tools

  • ChatGPT - AI assistance for resolving specific styling and structural challenges

๐Ÿ“ฝ๏ธ Screen recording

Screenshots