Skip to content

Commit

Permalink
your messages and other ones differ
Browse files Browse the repository at this point in the history
  • Loading branch information
deargosep committed Jan 24, 2022
1 parent a6291ff commit 19aa15b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
41 changes: 33 additions & 8 deletions lib/components/message.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';

class Message extends StatelessWidget {
Message({Key? key, required String this.text, required String this.author})
Message(
{Key? key,
required String this.text,
required String this.author,
required String this.authorId})
: super(key: key);
String authorId;
String text;
String author;

Expand All @@ -11,13 +17,32 @@ class Message extends StatelessWidget {
if (text == "") {
return Container();
}
return Container(
margin: EdgeInsets.all(5),
child: Card(
child: ListTile(
title: Text(text),
subtitle: Text(author),
bool getCurrentUser() {
final uid = FirebaseAuth.instance.currentUser?.uid;
if (authorId == uid) {
return true;
} else {
return false;
}
}

return Row(
mainAxisAlignment:
getCurrentUser() ? MainAxisAlignment.end : MainAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.all(5),
child: SizedBox(
width: 300,
child: Card(
child: ListTile(
title: Text(text),
subtitle: Text(author),
),
),
),
));
),
],
);
}
}
9 changes: 6 additions & 3 deletions lib/screens/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ChatScreen extends HookWidget {
final ScrollController _scrollController = ScrollController();
void send() {
final displayName = FirebaseAuth.instance.currentUser?.displayName;
final email = FirebaseAuth.instance.currentUser?.email;
final userId = FirebaseAuth.instance.currentUser?.uid;
FirebaseFirestore.instance
.collection('Chats')
Expand All @@ -30,7 +31,7 @@ class ChatScreen extends HookWidget {
.add({
"at": Timestamp.now(),
"text": messageController.value.text,
"author": displayName,
"author": displayName ?? email,
"authorId": userId
});
messageController.value = TextEditingValue.empty;
Expand Down Expand Up @@ -80,8 +81,10 @@ class ChatScreen extends HookWidget {
// );

return Message(
text: data['text'].toString(),
author: data['author'].toString());
text: data['text'].toString(),
author: data['author'].toString(),
authorId: data['authorId'].toString(),
);
}).toList(),
);
},
Expand Down

0 comments on commit 19aa15b

Please sign in to comment.