Skip to content

Commit 8cc6b29

Browse files
author
Franco Bugnano
committed
Implemented the highlightedWords property
1 parent 505b3e8 commit 8cc6b29

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/src/chatbox.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class ChatBox extends StatefulWidget {
4848
final TranslationToggle? showTranslationToggle;
4949
final String? theme;
5050
final TranslateConversations? translateConversations;
51+
final List<String> highlightedWords;
5152

5253
final Conversation? conversation;
5354
final bool? asGuest;
@@ -64,6 +65,7 @@ class ChatBox extends StatefulWidget {
6465
this.showTranslationToggle,
6566
this.theme,
6667
this.translateConversations,
68+
this.highlightedWords = const <String>[],
6769
this.conversation,
6870
this.asGuest,
6971
this.onSendMessage,
@@ -101,6 +103,7 @@ class ChatBoxState extends State<ChatBox> {
101103

102104
/// Objects stored for comparing changes
103105
ChatBoxOptions? _oldOptions;
106+
List<String> _oldHighlightedWords = [];
104107
bool? _oldAsGuest;
105108
Conversation? _oldConversation;
106109

@@ -118,6 +121,7 @@ class ChatBoxState extends State<ChatBox> {
118121

119122
_createSession();
120123
_createChatBox();
124+
_setHighlightedWords();
121125
_createConversation();
122126

123127
execute('chatBox.mount(document.getElementById("talkjs-container"));');
@@ -130,8 +134,10 @@ class ChatBoxState extends State<ChatBox> {
130134
final chatBoxRecreated = _checkRecreateChatBox();
131135

132136
if (chatBoxRecreated) {
137+
_setHighlightedWords();
133138
_createConversation();
134139
} else {
140+
_checkHighlightedWords();
135141
_checkRecreateConversation();
136142
}
137143

@@ -237,6 +243,22 @@ class ChatBoxState extends State<ChatBox> {
237243
return false;
238244
}
239245

246+
void _setHighlightedWords() {
247+
_oldHighlightedWords = List<String>.of(widget.highlightedWords);
248+
249+
execute('chatBox.setHighlightedWords(${json.encode(_oldHighlightedWords)});');
250+
}
251+
252+
bool _checkHighlightedWords() {
253+
if (!listEquals(widget.highlightedWords, _oldHighlightedWords)) {
254+
_setHighlightedWords();
255+
256+
return true;
257+
}
258+
259+
return false;
260+
}
261+
240262
void _webViewCreatedCallback(WebViewController webViewController) async {
241263
if (kDebugMode) {
242264
print('📗 chatbox._webViewCreatedCallback');

0 commit comments

Comments
 (0)