fyrechat 0.0.9
fyrechat: ^0.0.9 copied to clipboard
A Firebase-based Flutter chat core package supporting direct and group messaging with seen status, message replies, and Firestore integration.
π¦ Installation #
Add this to your pubspec.yaml:
dependencies:
firechat: <latest_version>
π Getting Started #
Check out the full example project on GitHub:
π Example App on GitHub
1. Initialize Firebase #
Make sure youβve initialized Firebase in your app:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
2. Use the Singleton Instance #
final fireChat = FyreChat.instance;
π οΈ Usage Examples #
π Listen to Current User #
fireChat.firebaseUser.listen((user) {
print('Current user: ${user?.uid}');
});
π§β Create User in Firestore #
await fireChat.createUserInFirestore(
uid: 'user_123',
name: 'John',
imageUrl: 'https://example.com/avatar.png',
);
π¬ Send a Text Message #
await fireChat.sendMessage(
roomId: 'room_abc',
author: yourUser,
text: 'Hello there!',
);
π¬ Send a Message with Reply #
await fireChat.sendMessageReply(
roomId: 'room_abc',
author: yourUser,
text: 'This is a reply!',
repliedMessage: originalMessage,
);
π§βπ€βπ§ Create a Direct Chat Room #
final room = await fireChat.createRoom(
user1Id: 'user_a',
user2Id: 'user_b',
);
π₯ Create a Group Room #
final room = await fireChat.createGroupRoom(
userIds: ['user1', 'user2', 'user3'],
currentUser: yourUser,
groupName: 'Study Group',
groupImage: 'https://example.com/group.png',
);
π Listen to Messages in a Room #
fireChat.messages('room_abc').listen((messages) {
for (var msg in messages) {
print('${msg.author.id}: ${msg.text}');
}
});
π Mark Messages as Seen #
This is automatic when streaming messages, but you can implement manual seen marking if needed:
await fireChat.markMessagesAsSeen(
roomId: 'room_abc',
userId: 'your_user_id',
);
π Firestore Structure #
Hereβs an example structure used by FyreChat:
Firestore Root
βββ rooms (Collection)
β βββ {roomId} (Document)
β βββ userIds: [uid1, uid2]
β βββ type: 'group' or 'direct'
β βββ ...
β
βββ messages/{roomId} (Subcollection)
β βββ {messageId}
β βββ author: {id, name, imageUrl}
β βββ text / imageUrl / fileUrl
β βββ seenBy: { uid1: timestamp, uid2: timestamp }
β βββ metadata (including reply info)
π Requirements #
- Firebase (Firestore + Auth)
- Flutter 3.10 or newer
- Dart 3.x
π§ͺ Coming Soon #
- β Typing indicator support
- β Push notifications
- β Message editing
- β Group member roles (admin/mod)
π€ Contribution #
Contributions are welcome! Feel free to open issues or submit pull requests.
Setup for Development #
git clone https://github.com/khamenkhai/fyre_chat
cd firechat
flutter pub get
π License #
This project is licensed under the MIT License. See the LICENSE file for details.