firechat 0.0.2
firechat: ^0.0.2 copied to clipboard

Chat package that has complete chatting functionality using Firebase.

Firechat #

Firebase chat package for Flutter

Reference #

TODOs #

  • Make chat room and chat list singleton.
  • Use rxdart to notify all the event. No more render!

Overview #

  • Firechat does not support for file uploading since every app has different backends.
    • But it provides an interface for uploading photo and it should be very simple.

Resources #

  • Most of the code is coming from FireFlutter. It's worthy to check out FireFlutter README file.

Installation #

Packages #

  • crypto is for encrypting user id list for a room id.

Firebase Auth #

  • User must login Firebase before using any of firechat code.

Global Rooms and User Rooms #

  • Global rooms are the room information documents that are saved under /chat/global-rooms/list collection.

  • User rooms are the documents that has a room information for a single user.

  • The differnces of global and user rooms are;

    • A global room has room informations like admins, password(to enter the room), room title, blocked user list, and more of the room itself.
    • A user room has information of the relation between the user and the room. Like no of new messages, last message of the room, etc.

Logic of Chat Room Create #

  • Create global room
  • Send welcome messages to users (by creating user's room) in the global room.

Security Rules #

  • It's in firebase/firestore.rules

Test on Security Rules #

  • First setup Firebase project.

  • Then, install Firebase tools and login. % npm install -g firebase-tools

  • Then, log into Firebase % firebase login

  • Then, install npm for testing.

% cd firebase
% npm init -y
% npm i -D @firebase/rules-unit-testing
% npm i -D firebase-admin
% npm i -D mocha
  • Then, run Firestore emualtor
firebase emulators:start --only firestore   ; run firebase emulator
  • Then, edit MY_PROJECT_ID with your Firebase project ID in chat.js.

  • Then, run the test

./node_modules/.bin/mocha tests/chat.js

Developer Guideline #

Global varaibles #

room() {
  return ChatRoom.instance;
}
roomList() {
  return ChatRoomList.instance;
}

room().listen(() { ... });

Tests #

  • Read the comments on top of chat.test.dart to know how to run test code.
  • Run the test code like below
import 'package:firechat/chat.test.dart';
a.firebaseInitialized.listen((ready) { // when firebase initialized,
  if (ready == false) return;
  FireChatTest().roomCreateTest(); // call test.
});