Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from asi-pwr/chat-style
Browse files Browse the repository at this point in the history
user avatar in chat
  • Loading branch information
jakdor authored Sep 15, 2019
2 parents 89404e1 + 6ebb1e0 commit 0e2935b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
11 changes: 8 additions & 3 deletions lib/common/repository/continuous_messages_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ class ContinuousMessagesRepository {
.snapshots();
}

String getMyUserId(){
String getMyUserId() {
return _user.uid;
}


Stream<QuerySnapshot> sendMessage(String roomId, content) {
var docReference = _firestore
.collection("room")
Expand All @@ -32,8 +33,12 @@ class ContinuousMessagesRepository {
.document(DateTime.now().millisecondsSinceEpoch.toString());

_firestore.runTransaction((transaction) async {
await transaction
.set(docReference, {'userId': _user.uid, 'content': content, 'userName': _user.displayName});
await transaction.set(docReference, {
'userId': _user.uid,
'content': content,
'userName': _user.displayName,
'imgUrl' :_user.photoUrl
});
});
}
}
25 changes: 21 additions & 4 deletions lib/ui/chat/chat_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,31 @@ class _ChatPageState extends State<ChatPage> {
decoration: BoxDecoration(
color: Colors.lightGreenAccent,
borderRadius: BorderRadius.circular(8.0)),
child: Text(document['userName'] + ': ' + document['content'],
textAlign: _isItMe(document['userId'])
? TextAlign.right
: TextAlign.left),
child: _isItMe(document['userId'])
? _myMessage(document)
: _otherMessage(document),
margin: EdgeInsets.only(bottom: 10))
]);
}

Widget _myMessage(document) {
return Row(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
Padding(
padding: EdgeInsets.only(right: 5.0),
child: Text(document['content'], textAlign: TextAlign.right)),
CircleAvatar(backgroundImage: NetworkImage(document['imgUrl']))
]);
}

Widget _otherMessage(document) {
return Row(mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[
CircleAvatar(backgroundImage: NetworkImage(document['imgUrl'])),
Padding(
padding: EdgeInsets.only(left: 5.0),
child: Text(document['content'], textAlign: TextAlign.left))
]);
}

Widget buildInput() {
return Container(
child: Row(
Expand Down

0 comments on commit 0e2935b

Please sign in to comment.