Skip to content

Commit c575685

Browse files
committed
Fixes after PR
1 parent de9283c commit c575685

File tree

13 files changed

+191
-197
lines changed

13 files changed

+191
-197
lines changed

doc/advanced-usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class _MyHomePageState extends State<MyHomePage> {
284284
Widget build(BuildContext context) => Scaffold(
285285
body: Chat(
286286
messages: _messages,
287-
onAttachmentPressed: _handleAtachmentPressed,
287+
onAttachmentPressed: _handleAttachmentPressed,
288288
onMessageTap: _handleMessageTap,
289289
onPreviewDataFetched: _handlePreviewDataFetched,
290290
onSendPressed: _handleSendPressed,
@@ -298,7 +298,7 @@ class _MyHomePageState extends State<MyHomePage> {
298298
});
299299
}
300300
301-
void _handleAtachmentPressed() {
301+
void _handleAttachmentPressed() {
302302
showModalBottomSheet<void>(
303303
context: context,
304304
builder: (BuildContext context) => SafeArea(

example/assets/messages.json

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,19 @@
4747
"id": "82091008-a484-4a89-ae75-a22bf8d6f3ac",
4848
"lastName": "White"
4949
},
50-
"createdAt": 1655648400000,
50+
"createdAt": 1655648401000,
5151
"id": "64747b28-df19-4a0c-8c47-316dc3546e3c",
5252
"status": "seen",
5353
"text": "Here you go buddy! 💪",
5454
"type": "text"
5555
},
56-
{
57-
"author": {
58-
"firstName": "John",
59-
"id": "b4878b96-efbc-479a-8291-474ef323dec7",
60-
"imageUrl": "https://avatars.githubusercontent.com/u/14123304?v=4"
61-
},
62-
"createdAt": 1655648399000,
63-
"id": "4a202811-7d48-4ae9-8323-d764a56031ds",
64-
"status": "seen",
65-
"text": "FIRST UNSEEN\n\nVoluptatem voluptatum eos aut voluptatem occaecati. Quia ducimus vero molestiae molestiae illum illo nisi autem. Labore consectetur expedita illum consequatur inventore consequatur quasi voluptatem. Perspiciatis ut reprehenderit officiis animi voluptas.",
66-
"type": "text"
67-
},
6856
{
6957
"author": {
7058
"firstName": "Matthew",
7159
"id": "82091008-a484-4a89-ae75-a22bf8d6f3ac",
7260
"lastName": "White"
7361
},
74-
"createdAt": 1655648398000,
62+
"createdAt": 1655648400000,
7563
"id": "6a1a4351-cf05-4d0c-9d0f-47ed378b6112",
7664
"mimeType": "application/pdf",
7765
"name": "city_guide-madrid.pdf",
@@ -86,7 +74,7 @@
8674
"id": "4c2307ba-3d40-442f-b1ff-b271f63904ca",
8775
"lastName": "Doe"
8876
},
89-
"createdAt": 1655648397000,
77+
"createdAt": 1655624464000,
9078
"id": "38681a33-2563-42aa-957b-cfc12f791d16",
9179
"status": "seen",
9280
"text": "Matt, where is my Madrid guide?",

example/lib/main.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ class _ChatPageState extends State<ChatPage> {
5252
onMessageTap: _handleMessageTap,
5353
onPreviewDataFetched: _handlePreviewDataFetched,
5454
onSendPressed: _handleSendPressed,
55-
scrollToUnseenOptions: const ScrollToUnseenOptions(
56-
lastSeenMessageID: '6a1a4351-cf05-4d0c-9d0f-47ed378b6112',
57-
scrollOnOpen: true,
58-
),
5955
showUserAvatars: true,
6056
showUserNames: true,
6157
user: _user,

lib/flutter_chat_ui.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
library flutter_chat_ui;
22

3-
export 'package:scroll_to_index/scroll_to_index.dart' show AutoScrollController;
4-
53
export 'src/chat_l10n.dart';
64
export 'src/chat_theme.dart';
75
export 'src/models/bubble_rtl_alignment.dart';
@@ -21,6 +19,6 @@ export 'src/widgets/input_text_field_controller.dart';
2119
export 'src/widgets/message.dart';
2220
export 'src/widgets/send_button.dart';
2321
export 'src/widgets/text_message.dart';
24-
export 'src/widgets/unseen_message_banner.dart';
22+
export 'src/widgets/unread_header.dart';
2523
export 'src/widgets/user_avatar.dart';
2624
export 'src/widgets/user_name.dart';

lib/src/chat_l10n.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract class ChatL10n {
1111
required this.fileButtonAccessibilityLabel,
1212
required this.inputPlaceholder,
1313
required this.sendButtonAccessibilityLabel,
14-
required this.unseenMessagesBannerLabel,
14+
required this.unreadMessagesLabel,
1515
});
1616

1717
/// Accessibility label (hint) for the attachment button.
@@ -29,8 +29,8 @@ abstract class ChatL10n {
2929
/// Accessibility label (hint) for the send button.
3030
final String sendButtonAccessibilityLabel;
3131

32-
/// Label for the unseen messages banner.
33-
final String unseenMessagesBannerLabel;
32+
/// Label for the unread messages header.
33+
final String unreadMessagesLabel;
3434
}
3535

3636
/// Arabic l10n which extends [ChatL10n].
@@ -45,7 +45,7 @@ class ChatL10nAr extends ChatL10n {
4545
super.fileButtonAccessibilityLabel = 'ملف',
4646
super.inputPlaceholder = 'الرسالة',
4747
super.sendButtonAccessibilityLabel = 'إرسال',
48-
super.unseenMessagesBannerLabel = '?',
48+
super.unreadMessagesLabel = 'الرسائل غير المقروءة',
4949
});
5050
}
5151

@@ -61,7 +61,7 @@ class ChatL10nDe extends ChatL10n {
6161
super.fileButtonAccessibilityLabel = 'Datei',
6262
super.inputPlaceholder = 'Nachricht',
6363
super.sendButtonAccessibilityLabel = 'Senden',
64-
super.unseenMessagesBannerLabel = 'Ungelesene Nachrichten',
64+
super.unreadMessagesLabel = 'Ungelesene Nachrichten',
6565
});
6666
}
6767

@@ -77,7 +77,7 @@ class ChatL10nEn extends ChatL10n {
7777
super.fileButtonAccessibilityLabel = 'File',
7878
super.inputPlaceholder = 'Message',
7979
super.sendButtonAccessibilityLabel = 'Send',
80-
super.unseenMessagesBannerLabel = 'Unread messages',
80+
super.unreadMessagesLabel = 'Unread messages',
8181
});
8282
}
8383

@@ -93,7 +93,7 @@ class ChatL10nEs extends ChatL10n {
9393
super.fileButtonAccessibilityLabel = 'Archivo',
9494
super.inputPlaceholder = 'Mensaje',
9595
super.sendButtonAccessibilityLabel = 'Enviar',
96-
super.unseenMessagesBannerLabel = '?',
96+
super.unreadMessagesLabel = 'Mensajes no leídos',
9797
});
9898
}
9999

@@ -109,7 +109,7 @@ class ChatL10nKo extends ChatL10n {
109109
super.fileButtonAccessibilityLabel = '파일',
110110
super.inputPlaceholder = '메시지',
111111
super.sendButtonAccessibilityLabel = '보내기',
112-
super.unseenMessagesBannerLabel = '?',
112+
super.unreadMessagesLabel = '읽지 않은 메시지',
113113
});
114114
}
115115

@@ -125,7 +125,7 @@ class ChatL10nPl extends ChatL10n {
125125
super.fileButtonAccessibilityLabel = 'Plik',
126126
super.inputPlaceholder = 'Napisz wiadomość',
127127
super.sendButtonAccessibilityLabel = 'Wyślij',
128-
super.unseenMessagesBannerLabel = '?',
128+
super.unreadMessagesLabel = 'Nieprzeczytane wiadomości',
129129
});
130130
}
131131

@@ -141,7 +141,7 @@ class ChatL10nPt extends ChatL10n {
141141
super.fileButtonAccessibilityLabel = 'Arquivo',
142142
super.inputPlaceholder = 'Mensagem',
143143
super.sendButtonAccessibilityLabel = 'Enviar',
144-
super.unseenMessagesBannerLabel = '?',
144+
super.unreadMessagesLabel = 'Mensagens não lidas',
145145
});
146146
}
147147

@@ -157,7 +157,7 @@ class ChatL10nRu extends ChatL10n {
157157
super.fileButtonAccessibilityLabel = 'Файл',
158158
super.inputPlaceholder = 'Сообщение',
159159
super.sendButtonAccessibilityLabel = 'Отправить',
160-
super.unseenMessagesBannerLabel = '?',
160+
super.unreadMessagesLabel = 'Непрочитанные сообщения',
161161
});
162162
}
163163

@@ -173,7 +173,7 @@ class ChatL10nTr extends ChatL10n {
173173
super.fileButtonAccessibilityLabel = 'Dosya',
174174
super.inputPlaceholder = 'Mesaj yazın',
175175
super.sendButtonAccessibilityLabel = 'Gönder',
176-
super.unseenMessagesBannerLabel = '?',
176+
super.unreadMessagesLabel = 'Okunmamış Mesajlar',
177177
});
178178
}
179179

@@ -189,7 +189,7 @@ class ChatL10nUk extends ChatL10n {
189189
super.fileButtonAccessibilityLabel = 'Файл',
190190
super.inputPlaceholder = 'Повідомлення',
191191
super.sendButtonAccessibilityLabel = 'Надіслати',
192-
super.unseenMessagesBannerLabel = '?',
192+
super.unreadMessagesLabel = 'Непрочитанi повідомлення',
193193
});
194194
}
195195

@@ -205,7 +205,7 @@ class ChatL10nZhCN extends ChatL10n {
205205
super.fileButtonAccessibilityLabel = '文件',
206206
super.inputPlaceholder = '输入消息',
207207
super.sendButtonAccessibilityLabel = '发送',
208-
super.unseenMessagesBannerLabel = '?',
208+
super.unreadMessagesLabel = '未读消息',
209209
});
210210
}
211211

@@ -221,6 +221,6 @@ class ChatL10nZhTW extends ChatL10n {
221221
super.fileButtonAccessibilityLabel = '檔案',
222222
super.inputPlaceholder = '輸入訊息',
223223
super.sendButtonAccessibilityLabel = '傳送',
224-
super.unseenMessagesBannerLabel = '?',
224+
super.unreadMessagesLabel = '未讀訊息',
225225
});
226226
}

lib/src/chat_theme.dart

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:flutter/material.dart';
22

3+
import 'widgets/unread_header.dart';
4+
35
// For internal usage only. Use values from theme itself.
46

57
/// See [ChatTheme.userAvatarNameColors]
@@ -96,7 +98,7 @@ abstract class ChatTheme {
9698
required this.sentMessageLinkDescriptionTextStyle,
9799
required this.sentMessageLinkTitleTextStyle,
98100
required this.statusIconPadding,
99-
required this.unseenMessagesBannerTheme,
101+
required this.unreadHeaderTheme,
100102
required this.userAvatarImageBackgroundColor,
101103
required this.userAvatarNameColors,
102104
required this.userAvatarTextStyle,
@@ -257,8 +259,8 @@ abstract class ChatTheme {
257259
/// Padding around status icons.
258260
final EdgeInsets statusIconPadding;
259261

260-
/// Theme for the unseen messages banner.
261-
final UnseenMessagesBannerTheme unseenMessagesBannerTheme;
262+
/// Theme for the unread header.
263+
final UnreadHeaderTheme unreadHeaderTheme;
262264

263265
/// Color used as a background for user avatar if an image is provided.
264266
/// Visible if the image has some transparent parts.
@@ -394,7 +396,7 @@ class DefaultChatTheme extends ChatTheme {
394396
height: 1.375,
395397
),
396398
super.statusIconPadding = const EdgeInsets.symmetric(horizontal: 4),
397-
super.unseenMessagesBannerTheme = const UnseenMessagesBannerTheme(
399+
super.unreadHeaderTheme = const UnreadHeaderTheme(
398400
color: secondary,
399401
textStyle: TextStyle(
400402
color: neutral2,
@@ -536,7 +538,7 @@ class DarkChatTheme extends ChatTheme {
536538
height: 1.375,
537539
),
538540
super.statusIconPadding = const EdgeInsets.symmetric(horizontal: 4),
539-
super.unseenMessagesBannerTheme = const UnseenMessagesBannerTheme(
541+
super.unreadHeaderTheme = const UnreadHeaderTheme(
540542
color: secondaryDark,
541543
textStyle: TextStyle(
542544
color: neutral7WithOpacity,
@@ -560,17 +562,3 @@ class DarkChatTheme extends ChatTheme {
560562
),
561563
});
562564
}
563-
564-
@immutable
565-
class UnseenMessagesBannerTheme {
566-
const UnseenMessagesBannerTheme({
567-
required this.color,
568-
required this.textStyle,
569-
});
570-
571-
/// Background color of the banner.
572-
final Color color;
573-
574-
/// Text style for the unseen message banner text.
575-
final TextStyle textStyle;
576-
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'package:equatable/equatable.dart';
2+
import 'package:meta/meta.dart';
3+
4+
/// A class that represents the header above the first unread message.
5+
@immutable
6+
class UnreadHeaderData extends Equatable {
7+
const UnreadHeaderData({
8+
this.marginTop,
9+
});
10+
11+
final double? marginTop;
12+
13+
@override
14+
List<Object?> get props => [];
15+
}

lib/src/models/unseen_banner.dart

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/src/util.dart

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import 'package:flutter/foundation.dart' show kIsWeb;
55
import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
66
import 'package:intl/intl.dart';
77

8-
import './models/date_header.dart';
9-
import './models/emoji_enlargement_behavior.dart';
10-
import './models/message_spacer.dart';
11-
import './models/preview_image.dart';
12-
import 'models/unseen_banner.dart';
8+
import 'models/date_header.dart';
9+
import 'models/emoji_enlargement_behavior.dart';
10+
import 'models/message_spacer.dart';
11+
import 'models/preview_image.dart';
12+
import 'models/unread_header_data.dart';
1313

1414
/// Returns text representation of a provided bytes value (e.g. 1kB, 1GB).
1515
String formatBytes(int size, [int fractionDigits = 2]) {
@@ -96,17 +96,17 @@ bool isConsistsOfEmojis(
9696
return multiEmojiRegExp.hasMatch(message.text);
9797
}
9898

99-
/// Parses provided messages to chat messages (with headers, unseen banner
100-
/// and spacers) and returns them with a gallery
99+
/// Parses provided messages to chat messages (with headers and spacers)
100+
/// and returns them with a gallery.
101101
List<Object> calculateChatMessages(
102102
List<types.Message> messages,
103103
types.User user, {
104104
String Function(DateTime)? customDateHeaderText,
105105
DateFormat? dateFormat,
106106
required int dateHeaderThreshold,
107107
String? dateLocale,
108-
String? lastSeenMessageID,
109108
required int groupMessagesThreshold,
109+
String? lastReadMessageId,
110110
required bool showUserNames,
111111
DateFormat? timeFormat,
112112
}) {
@@ -164,7 +164,7 @@ List<Object> calculateChatMessages(
164164
DateTime.fromMillisecondsSinceEpoch(nextMessage.createdAt!).day;
165165

166166
nextMessageInGroup = nextMessageSameAuthor &&
167-
message.id != lastSeenMessageID &&
167+
message.id != lastReadMessageId &&
168168
nextMessage.createdAt! - message.createdAt! <= groupMessagesThreshold;
169169
}
170170

@@ -224,8 +224,14 @@ List<Object> calculateChatMessages(
224224
);
225225
}
226226

227-
if (message.id == lastSeenMessageID && !isLast) {
228-
chatMessages.insert(0, const UnseenBanner());
227+
if (message.id == lastReadMessageId && !isLast) {
228+
chatMessages.insert(
229+
0,
230+
UnreadHeaderData(
231+
marginTop:
232+
nextMessageDifferentDay || nextMessageDateThreshold ? 0 : 8,
233+
),
234+
);
229235
}
230236

231237
if (message is types.ImageMessage) {

0 commit comments

Comments
 (0)