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

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




