From 7f94271ea2f77dbacc200cda6971b7c0c8ce0892 Mon Sep 17 00:00:00 2001 From: Lucas Gabriel <90lucasgabriel@gmail.com> Date: Sun, 18 Apr 2021 11:35:53 -0300 Subject: [PATCH] 09 - New: Chat message info; --- lib/ui/chat_screen.dart | 8 +++-- lib/widgets/chat_message.dart | 60 +++++++++++++++++++++++++++++++++++ lib/widgets/input.dart | 1 + web/index.html | 1 + 4 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 lib/widgets/chat_message.dart diff --git a/lib/ui/chat_screen.dart b/lib/ui/chat_screen.dart index 9c6613e..a1ad98b 100644 --- a/lib/ui/chat_screen.dart +++ b/lib/ui/chat_screen.dart @@ -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 { @@ -51,8 +52,11 @@ class _ChatScreenState extends State { ScaffoldMessenger.of(context).removeCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar(snackbar); + + return; } + print(user); Map data = { 'senderUid': user.uid, 'senderName': user.displayName, @@ -113,9 +117,7 @@ class _ChatScreenState extends State { itemCount: documentList.length, reverse: true, itemBuilder: (context, index) { - return ListTile( - title: Text(documentList[index].data()['value']), - ); + return ChatMessage(documentList[index].data(), true); }, ); } diff --git a/lib/widgets/chat_message.dart b/lib/widgets/chat_message.dart new file mode 100644 index 0000000..643ac95 --- /dev/null +++ b/lib/widgets/chat_message.dart @@ -0,0 +1,60 @@ +import 'package:flutter/material.dart'; + +class ChatMessage extends StatelessWidget { + /// Props + /// Message info + final Map 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']), + ), + ), + ], + ), + ); + } +} diff --git a/lib/widgets/input.dart b/lib/widgets/input.dart index adff8ac..d2c9c32 100644 --- a/lib/widgets/input.dart +++ b/lib/widgets/input.dart @@ -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; diff --git a/web/index.html b/web/index.html index 70e8d40..a0e3802 100644 --- a/web/index.html +++ b/web/index.html @@ -43,6 +43,7 @@ +