@@ -22,6 +22,7 @@ typedef SendMessageHandler = void Function(SendMessageEvent event);
2222typedef TranslationToggledHandler = void Function (TranslationToggledEvent event);
2323typedef LoadingStateHandler = void Function (LoadingState state);
2424typedef MessageActionHandler = void Function (MessageActionEvent event);
25+ typedef NavigationHandler = UrlNavigationAction Function (UrlNavigationRequest navigationRequest);
2526
2627class SendMessageEvent {
2728 final ConversationData conversation;
@@ -54,6 +55,16 @@ class MessageActionEvent {
5455 message = Message .fromJson (json['message' ]);
5556}
5657
58+ enum UrlNavigationAction { allow, deny }
59+
60+ class UrlNavigationRequest {
61+ final String url;
62+
63+ UrlNavigationRequest (
64+ this .url,
65+ );
66+ }
67+
5768/// A messaging UI for just a single conversation.
5869///
5970/// Create a Chatbox through [Session.createChatbox] and then call [mount] to show it.
@@ -77,6 +88,7 @@ class ChatBox extends StatefulWidget {
7788 final TranslationToggledHandler ? onTranslationToggled;
7889 final LoadingStateHandler ? onLoadingStateChanged;
7990 final Map <String , MessageActionHandler >? onCustomMessageAction;
91+ final NavigationHandler ? onUrlNavigation;
8092
8193 const ChatBox ({
8294 Key ? key,
@@ -95,6 +107,7 @@ class ChatBox extends StatefulWidget {
95107 this .onTranslationToggled,
96108 this .onLoadingStateChanged,
97109 this .onCustomMessageAction,
110+ this .onUrlNavigation,
98111 }) : super (key: key);
99112
100113 @override
@@ -221,6 +234,7 @@ class ChatBoxState extends State<ChatBox> {
221234 // We need only the VerticalDragGestureRecognizer in order to be able to scroll through the messages
222235 Factory (() => VerticalDragGestureRecognizer ()),
223236 },
237+ navigationDelegate: _shouldNavigateToUrl,
224238 );
225239 }
226240
@@ -451,6 +465,25 @@ class ChatBoxState extends State<ChatBox> {
451465 widget.onCustomMessageAction? [action]? .call (MessageActionEvent .fromJson (jsonMessage));
452466 }
453467
468+ FutureOr <NavigationDecision > _shouldNavigateToUrl (
469+ NavigationRequest navigationRequest,
470+ ) {
471+ if (widget.onUrlNavigation != null ) {
472+ final UrlNavigationAction action = widget.onUrlNavigation !(
473+ UrlNavigationRequest (navigationRequest.url),
474+ );
475+
476+ switch (action) {
477+ case UrlNavigationAction .allow:
478+ return NavigationDecision .navigate;
479+ case UrlNavigationAction .deny:
480+ return NavigationDecision .prevent;
481+ }
482+ }
483+
484+ return NavigationDecision .navigate;
485+ }
486+
454487 /// For internal use only. Implementation detail that may change anytime.
455488 ///
456489 /// Return a string with a unique ID
0 commit comments