Skip to content

Commit

Permalink
Merge pull request #9 from 90lucasgabriel/09-message-info
Browse files Browse the repository at this point in the history
09 - Chat message info
  • Loading branch information
90lucasgabriel committed Apr 18, 2021
2 parents f071a24 + 7f94271 commit ebcdbc0
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/ui/chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'dart:io';

import 'package:chat/widgets/chat_message.dart';
import 'package:chat/widgets/input.dart';

class ChatScreen extends StatefulWidget {
Expand Down Expand Up @@ -51,8 +52,11 @@ class _ChatScreenState extends State<ChatScreen> {

ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(snackbar);

return;
}

print(user);
Map<String, dynamic> data = {
'senderUid': user.uid,
'senderName': user.displayName,
Expand Down Expand Up @@ -113,9 +117,7 @@ class _ChatScreenState extends State<ChatScreen> {
itemCount: documentList.length,
reverse: true,
itemBuilder: (context, index) {
return ListTile(
title: Text(documentList[index].data()['value']),
);
return ChatMessage(documentList[index].data(), true);
},
);
}
Expand Down
60 changes: 60 additions & 0 deletions lib/widgets/chat_message.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'package:flutter/material.dart';

class ChatMessage extends StatelessWidget {
/// Props
/// Message info
final Map<String, dynamic> data;

/// Check if message is mine
final bool isOwner;

/// Constructor
ChatMessage(this.data, this.isOwner);

@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(vertical: 8, horizontal: 8),
child: Row(
children: [
if (!isOwner)
Container(
padding: EdgeInsets.only(right: 8),
child: CircleAvatar(
backgroundImage: NetworkImage(data['senderPhotoUrl']),
),
),
Expanded(
child: Column(
crossAxisAlignment:
isOwner ? CrossAxisAlignment.end : CrossAxisAlignment.start,
children: [
data['imageUrl'] != null
? Image.network(
data['imageUrl'],
width: 250,
)
: Text(
data['value'],
textAlign: isOwner ? TextAlign.end : TextAlign.start,
style: TextStyle(fontSize: 14),
),
Text(
data['senderName'],
style: TextStyle(fontSize: 10, fontWeight: FontWeight.w300),
),
],
),
),
if (isOwner)
Container(
padding: EdgeInsets.only(left: 8),
child: CircleAvatar(
backgroundImage: NetworkImage(data['senderPhotoUrl']),
),
),
],
),
);
}
}
1 change: 1 addition & 0 deletions lib/widgets/input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:image_picker/image_picker.dart';

class Input extends StatefulWidget {
/// Props
/// Send message to Firebase
final Function({String value, File file}) sendMessage;

Expand Down
1 change: 1 addition & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<script src="https://www.gstatic.com/firebasejs/8.4.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.4.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.4.1/firebase-storage.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.4.1/firebase-auth.js"></script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>

0 comments on commit ebcdbc0

Please sign in to comment.