@@ -30,6 +30,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
30
30
static final light = MessageListTheme ._(
31
31
dateSeparator: Colors .black,
32
32
dateSeparatorText: const HSLColor .fromAHSL (0.75 , 0 , 0 , 0.15 ).toColor (),
33
+ dmMessageBgDefault: const HSLColor .fromAHSL (1 , 45 , 0.20 , 0.96 ).toColor (),
33
34
dmRecipientHeaderBg: const HSLColor .fromAHSL (1 , 46 , 0.35 , 0.93 ).toColor (),
34
35
messageTimestamp: const HSLColor .fromAHSL (0.8 , 0 , 0 , 0.2 ).toColor (),
35
36
recipientHeaderText: const HSLColor .fromAHSL (1 , 0 , 0 , 0.15 ).toColor (),
@@ -55,6 +56,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
55
56
static final dark = MessageListTheme ._(
56
57
dateSeparator: Colors .white,
57
58
dateSeparatorText: const HSLColor .fromAHSL (0.75 , 0 , 0 , 1 ).toColor (),
59
+ dmMessageBgDefault: const HSLColor .fromAHSL (1 , 46 , 0.07 , 0.16 ).toColor (),
58
60
dmRecipientHeaderBg: const HSLColor .fromAHSL (1 , 46 , 0.15 , 0.2 ).toColor (),
59
61
messageTimestamp: const HSLColor .fromAHSL (0.8 , 0 , 0 , 0.85 ).toColor (),
60
62
recipientHeaderText: const HSLColor .fromAHSL (0.8 , 0 , 0 , 1 ).toColor (),
@@ -79,6 +81,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
79
81
MessageListTheme ._({
80
82
required this .dateSeparator,
81
83
required this .dateSeparatorText,
84
+ required this .dmMessageBgDefault,
82
85
required this .dmRecipientHeaderBg,
83
86
required this .messageTimestamp,
84
87
required this .recipientHeaderText,
@@ -103,6 +106,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
103
106
104
107
final Color dateSeparator;
105
108
final Color dateSeparatorText;
109
+ final Color dmMessageBgDefault;
106
110
final Color dmRecipientHeaderBg;
107
111
final Color messageTimestamp;
108
112
final Color recipientHeaderText;
@@ -118,6 +122,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
118
122
MessageListTheme copyWith ({
119
123
Color ? dateSeparator,
120
124
Color ? dateSeparatorText,
125
+ Color ? dmMessageBgDefault,
121
126
Color ? dmRecipientHeaderBg,
122
127
Color ? messageTimestamp,
123
128
Color ? recipientHeaderText,
@@ -132,6 +137,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
132
137
return MessageListTheme ._(
133
138
dateSeparator: dateSeparator ?? this .dateSeparator,
134
139
dateSeparatorText: dateSeparatorText ?? this .dateSeparatorText,
140
+ dmMessageBgDefault: dmMessageBgDefault ?? this .dmMessageBgDefault,
135
141
dmRecipientHeaderBg: dmRecipientHeaderBg ?? this .dmRecipientHeaderBg,
136
142
messageTimestamp: messageTimestamp ?? this .messageTimestamp,
137
143
recipientHeaderText: recipientHeaderText ?? this .recipientHeaderText,
@@ -153,6 +159,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
153
159
return MessageListTheme ._(
154
160
dateSeparator: Color .lerp (dateSeparator, other.dateSeparator, t)! ,
155
161
dateSeparatorText: Color .lerp (dateSeparatorText, other.dateSeparatorText, t)! ,
162
+ dmMessageBgDefault: Color .lerp (dmMessageBgDefault, other.dmMessageBgDefault, t)! ,
156
163
dmRecipientHeaderBg: Color .lerp (streamMessageBgDefault, other.dmRecipientHeaderBg, t)! ,
157
164
messageTimestamp: Color .lerp (messageTimestamp, other.messageTimestamp, t)! ,
158
165
recipientHeaderText: Color .lerp (recipientHeaderText, other.recipientHeaderText, t)! ,
@@ -167,6 +174,14 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
167
174
}
168
175
}
169
176
177
+ /// Helper function to get the background color for a message based on its type.
178
+ Color getMessageBackgroundColor (Message message, MessageListTheme messageListTheme) {
179
+ return switch (message) {
180
+ StreamMessage () => messageListTheme.streamMessageBgDefault,
181
+ DmMessage () => messageListTheme.dmMessageBgDefault,
182
+ };
183
+ }
184
+
170
185
/// The interface for the state of a [MessageListPage] .
171
186
///
172
187
/// To obtain one of these, see [MessageListPage.ancestorOf] .
@@ -924,8 +939,9 @@ class DateSeparator extends StatelessWidget {
924
939
925
940
final line = BorderSide (width: 0 , color: messageListTheme.dateSeparator);
926
941
927
- // TODO(#681) use different color for DM messages
928
- return ColoredBox (color: messageListTheme.streamMessageBgDefault,
942
+ final backgroundColor = getMessageBackgroundColor (message, messageListTheme);
943
+
944
+ return ColoredBox (color: backgroundColor,
929
945
child: Padding (
930
946
padding: const EdgeInsets .symmetric (vertical: 8 , horizontal: 2 ),
931
947
child: Row (children: [
@@ -966,13 +982,16 @@ class MessageItem extends StatelessWidget {
966
982
Widget build (BuildContext context) {
967
983
final message = item.message;
968
984
final messageListTheme = MessageListTheme .of (context);
985
+
986
+ final backgroundColor = getMessageBackgroundColor (message, messageListTheme);
987
+
969
988
return StickyHeaderItem (
970
989
allowOverflow: ! item.isLastInBlock,
971
990
header: header,
972
991
child: _UnreadMarker (
973
992
isRead: message.flags.contains (MessageFlag .read),
974
993
child: ColoredBox (
975
- color: messageListTheme.streamMessageBgDefault ,
994
+ color: backgroundColor ,
976
995
child: Column (children: [
977
996
MessageWithPossibleSender (item: item),
978
997
if (trailingWhitespace != null && item.isLastInBlock) SizedBox (height: trailingWhitespace! ),
0 commit comments