Skip to content

Instantly share code, notes, and snippets.

void onSendMessage(String content, int type) {
// type: 0 = text, 1 = image, 2 = sticker
if (content.trim() != '') {
textEditingController.clear();
var documentReference = Firestore.instance
.collection('messages')
.document(groupChatId)
.collection(groupChatId)
.document(DateTime.now().millisecondsSinceEpoch.toString());
document['type'] == 0
// Text
? Container(
child: Text(
document['content'],
style: TextStyle(color: primaryColor),
),
padding: EdgeInsets.fromLTRB(15.0, 10.0, 15.0, 10.0),
width: 200.0,
decoration: BoxDecoration(color: greyColor2, borderRadius: BorderRadius.circular(8.0)),
if (currentId.hashCode <= peerId.hashCode) {
groupChatId = '$currentId-$peerId';
} else {
groupChatId = '$peerId-$currentId';
}
constructor(props) {
super(props)
this.state = {
isKeyboardShow: false,
keyboardHeight: 0,
}
}
componentWillMount() {
this.keyboardDidShowListener = Keyboard.addListener(
import firebase from 'firebase'
const config = {
apiKey: 'AIzaSyAC9ZSyvTxU2o5W0jcL0hDvzS4utLuicE8',
authDomain: 'flutterchatdemo.firebaseapp.com',
databaseURL: 'https://flutterchatdemo.firebaseio.com',
projectId: 'flutterchatdemo',
storageBucket: 'flutterchatdemo.appspot.com',
messagingSenderId: '347976604232'
}
@duytq94
duytq94 / root.js
Last active August 12, 2019 16:08
render() {
return (
<BrowserRouter>
<div>
<ToastContainer
autoClose={2000}
hideProgressBar={true}
position={toast.POSITION.BOTTOM_RIGHT}
/>
<Switch>
myFirebase
.auth()
.signInWithPopup(new firebase.auth.GoogleAuthProvider())
.then(async result => {})
.catch(err => {})
@duytq94
duytq94 / main.js
Last active August 12, 2019 16:08
componentDidMount() {
this.checkLogin()
}
checkLogin = () => {
if (!localStorage.getItem(AppString.ID)) {
this.setState({
isLoading: false
}, () => {
this.props.history.push('/')
renderListUser = () => {
if (this.listUser.length > 0) {
let viewListUser = []
this.listUser.forEach((item, index) => {
if (item.data().id !== this.currentUserId) {
viewListUser.push(
<button
key={index}
className={
this.state.currentPeerUser &&
getListHistory = () => {
if (this.removeListener) {
this.removeListener()
}
this.listMessage.length = 0
this.setState({
isLoading: true
})
if (
this.hashString(this.currentUserId) <=