This is closed alpha version, please use it at your own risk
Your support is always welcome appreciated. It will boost me up to make better packages.
To use this plugin:
- Add
cloud_firestoreas a dependency in your pubspec.yaml file.
- Using the Firebase Console, add an Android app to your project.
- Follow the assistant, and download the generated
google-services.jsonfile and place it insideandroid/app. - Modify the
android/build.gradlefile and theandroid/app/build.gradlefile to add the Google services plugin as described by the Firebase assistant. Ensure that yourandroid/build.gradlefile contains themaven.google.comas described here.
- Using the Firebase Console, add an iOS app to your project.
- Follow the assistant, download the generated
GoogleService-Info.plistfile. Do NOT follow the steps named "Add Firebase SDK" and "Add initialization code" in the Firebase assistant. - Open
ios/Runner.xcworkspacewith Xcode, and within Xcode place theGoogleService-Info.plistfile insideios/Runner.
There are three main Module/Widgets we provide.
- ChatEngine - The core module of the package. It provides features like sending chat, clearning cache, removing db and more. This must be initialized at the beginning of the app start.
- ChatGroupList - This widget provides chat groups that is created for the user.
- ChatMessages - This widget provides chat messages for each chat groups.
Call ChatEngine.instance.initialize(); after the firebase is authenticated.
This initializes local database and start listening for chat groups' updates.
Set 'allowReadReceipts' to false if you want to avoid users to send 'message delivered flag' to opponents. Then, every user will not be able to get notify of whether the each user has read other's messages or not. This will reduce the read counts of messages on Firestore to half (4 -> 2).
Defaults to true, and recommended to use as default for the most of case. Consider using it for reducing read counts only.
Provides chat group list data.
Sample code
ChatGroupList(
builder: (context, chatGroups, child) {
if (chatGroups == null) {
return Center(
child: CircularProgressIndicator(),
);
} else {
return ListView.builder(
itemCount: chatGroups.length,
itemBuilder: (context, index) {
ChatUser opponentUser = chatGroups[index].getOpponentData(myUserId);
bool photoExist = opponentUser.avatarUrl != null && opponentUser.avatarUrl.length > 0;
// Some other codes
// return ChatMessages(...);
},
);
}
},
);Provides chat messages of selected chat group.
Sample code
ChatMessages(
groupId: chatGroupId,
builder: (context, messages, child) {
if (messages == null || messages.length < 1) {
return Container();
} else {
List<ChatMessage> chats = messages.reversed.toList();
// Some other codes
// return ListView(...);
}
},
);