flutter_inapp_chat 0.4.0
flutter_inapp_chat: ^0.4.0 copied to clipboard
A simple, complete chat system for Flutter with ready-to-use UI, image sharing, and view models, backed by Cloud Firestore, Appwrite, or Supabase.
Inapp Chatπ₯π¬ #
A simple, complete chat system for Flutter with ready-to-use UI, image sharing, and view models β backed by Cloud Firestore, Appwrite, or Supabase, your choice.
βοΈ Getting started #
Add Inapp Chat to your project by following the instructions on the install page, then import the core package plus the backend you want to use:
import 'package:flutter_inapp_chat/inapp_chat.dart';
import 'package:flutter_inapp_chat/backends/firestore_chat_backend.dart';
// or: 'package:flutter_inapp_chat/backends/appwrite_chat_backend.dart'
// or: 'package:flutter_inapp_chat/backends/supabase_chat_backend.dart'
Importing only the backend(s) you use keeps cloud_firestore/
firebase_storage, appwrite, and supabase_flutter out of your build
unless you actually reference them β package:flutter_inapp_chat/inapp_chat.dart
itself stays backend-agnostic.
You can open chat page either via Material route or directly push the chat page
await openChatPage(BuildContext context, ChatEntity chatEntity);
or
InappChat().chatPageWidget(chatEntity)
π± Example #
Opening chat #
final chatEntity = ChatEntity(
onMessageSent: (message, chatEntity){
//
},
mainUser: mainUser,
peers: peers,
backend: FirestoreChatBackend(),
path: chatPath,
title: "FIFA 2022 Games",
);
//WAY 1
Navigator.push(
context,
InappChat().chatPageWidget(chatEntity),
);
//WAY 2
await openChatPage(context, chatEntity);
...
π Backends #
Every backend implements the same ChatBackend interface (load history,
stream new messages, send a message, upload an image), so switching
providers only means constructing a different one and handing it to
ChatEntity.backend. path identifies where a conversation's messages live,
in whatever form the chosen backend expects.
Firestore #
ChatEntity(
backend: FirestoreChatBackend(),
path: "sport/football/2022/worldcup", // Firestore collection path
...
);
Messages are stored in the <path>/Activity subcollection. Requires
cloud_firestore and firebase_storage to be configured for your app
(Firebase.initializeApp(...)).
Appwrite #
ChatEntity(
backend: AppwriteChatBackend(
endpoint: "https://cloud.appwrite.io/v1",
projectId: "<project-id>",
databaseId: "<database-id>",
bucketId: "<bucket-id>",
),
path: "worldcup-2022", // Appwrite table id
...
);
Each conversation is a table in databaseId, with one row per message and a
timestamp string column (ISO 8601). Enable Realtime for the table.
Supabase #
ChatEntity(
backend: SupabaseChatBackend(bucketName: "chat-images"),
path: "worldcup_2022", // Supabase table name
...
);
Requires Supabase.initialize(url: ..., anonKey: ...) to have run first.
Each conversation is a Postgres table with an id (uuid, default
gen_random_uuid()) primary key and a timestamp timestamptz column
(default now()), with Realtime enabled.
Models π¦ #
Peer User π¨
Fields
id- user Idimage- user image urlname- user display name
Chat Entity π© #
Fields
mainUser- logged in userpeers- Map of users<user ID, PeerUser>backend- theChatBackendstoring this chat (FirestoreChatBackend,AppwriteChatBackend, orSupabaseChatBackend)title- name of the chat (You can name group chats, can benullable)path- where the messages/chat are stored, in the formbackendexpectsonMessageSent- callback for when the message is saved
License βοΈ #
Issues and feedback π #
If you have any suggestion for including a feature or if something doesn't work, feel free to open a Github issue for us to have a discussion on it.