Skip to content

Commit b84849b

Browse files
committed
Different layout if the message sender is the current user.
1 parent 5f910f7 commit b84849b

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

assets/changelog.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"version": "1.2.0",
2+
"version": "1.2.2",
33
"changes": [
44
{
5-
"title": "🔑 Password reset now available.",
6-
"body": "Users can now reset their password from the login screen."
5+
"title": "🐛 Bug fixes:",
6+
"body": "Logout from email verification screen, Login/Signup progress indicator, Different layout for user message."
77
}
88
]
99
}

lib/components/message_widget.dart

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:monochat/components/user_image.dart';
3+
import 'package:monochat/models/current_user_dao.dart';
34
import 'package:provider/provider.dart';
45
import 'package:intl/intl.dart';
56
import 'package:monochat/models/user_dao.dart';
@@ -26,11 +27,60 @@ class MessageWidget extends StatelessWidget {
2627
Widget build(BuildContext context) {
2728
Future<Map<String, dynamic>> userDataFuture =
2829
Provider.of<UserDao>(context, listen: false).getUserData(uid);
30+
if (uid == Provider.of<CurrentUserDao>(context, listen: false).userId()) {
31+
return currentUserMessage(context, userDataFuture);
32+
} else {
33+
return otherUserMessage(context, userDataFuture);
34+
}
35+
}
36+
37+
Widget currentUserMessage(context, userDataFuture) {
38+
return Column(crossAxisAlignment: CrossAxisAlignment.end, children: [
39+
Row(
40+
mainAxisAlignment: MainAxisAlignment.end,
41+
children: [
42+
ConstrainedBox(
43+
constraints: const BoxConstraints(maxWidth: 250),
44+
child: Container(
45+
decoration: BoxDecoration(
46+
color: Theme.of(context).cardColor,
47+
borderRadius: const BorderRadius.all(
48+
Radius.circular(15),
49+
),
50+
),
51+
child: Padding(
52+
padding: const EdgeInsets.all(12.0),
53+
child: Text(message),
54+
),
55+
),
56+
),
57+
const SizedBox(
58+
width: 5,
59+
),
60+
FutureBuilder<Map<String, dynamic>>(
61+
future: userDataFuture,
62+
builder: (con, snapshot) {
63+
return UserImage(uid);
64+
}),
65+
],
66+
),
67+
Padding(
68+
padding: const EdgeInsets.only(right: 55),
69+
child: Text(
70+
DateFormat(date.isSameDate(DateTime.now())
71+
? 'h:mm a'
72+
: 'LLL d • h:mm a')
73+
.format(date)
74+
.toString(),
75+
style: const TextStyle(color: Colors.grey, fontSize: 12))),
76+
]);
77+
}
78+
79+
Widget otherUserMessage(context, userDataFuture) {
2980
return Column(
3081
crossAxisAlignment: CrossAxisAlignment.start,
3182
children: [
3283
Row(
33-
crossAxisAlignment: CrossAxisAlignment.end,
3484
children: [
3585
FutureBuilder<Map<String, dynamic>>(
3686
future: userDataFuture,

lib/screens/changelog_screen.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'dart:convert';
2-
import 'package:flutter/cupertino.dart';
32
import 'package:flutter/material.dart';
43
import 'package:flutter/services.dart';
54
import 'package:shared_preferences/shared_preferences.dart';
@@ -44,7 +43,7 @@ class ChangelogScreen extends StatelessWidget {
4443
style: Theme.of(context).textTheme.headline5,
4544
),
4645
const SizedBox(
47-
height: 10,
46+
height: 20,
4847
),
4948
Expanded(
5049
child: ListView.builder(

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1515
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
1616
# Read more about iOS versioning at
1717
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18-
version: 1.2.1
18+
version: 1.2.2
1919

2020
environment:
2121
sdk: ">=2.15.0 <3.0.0"

0 commit comments

Comments
 (0)