@@ -20,6 +20,7 @@ typedef SendMessageHandler = void Function(SendMessageEvent event);
2020typedef TranslationToggledHandler = void Function (TranslationToggledEvent event);
2121typedef LoadingStateHandler = void Function (LoadingState state);
2222typedef MessageActionHandler = void Function (MessageActionEvent event);
23+ typedef NavigationHandler = UrlNavigationAction Function (UrlNavigationRequest navigation);
2324
2425class SendMessageEvent {
2526 final ConversationData conversation;
@@ -52,6 +53,13 @@ class MessageActionEvent {
5253 message = Message .fromJson (json['message' ]);
5354}
5455
56+ enum UrlNavigationAction { allow, deny }
57+
58+ class UrlNavigationRequest {
59+ final url;
60+ UrlNavigationRequest (this .url);
61+ }
62+
5563/// A messaging UI for just a single conversation.
5664///
5765/// Create a Chatbox through [Session.createChatbox] and then call [mount] to show it.
@@ -75,7 +83,7 @@ class ChatBox extends StatefulWidget {
7583 final TranslationToggledHandler ? onTranslationToggled;
7684 final LoadingStateHandler ? onLoadingStateChanged;
7785 final Map <String , MessageActionHandler >? onCustomMessageAction;
78- final NavigationDelegate ? navigationDelegate ;
86+ final NavigationHandler ? onUrlNavigation ;
7987
8088 const ChatBox ({
8189 Key ? key,
@@ -94,7 +102,7 @@ class ChatBox extends StatefulWidget {
94102 this .onTranslationToggled,
95103 this .onLoadingStateChanged,
96104 this .onCustomMessageAction,
97- this .navigationDelegate ,
105+ this .onUrlNavigation ,
98106 }) : super (key: key);
99107
100108 @override
@@ -201,7 +209,7 @@ class ChatBoxState extends State<ChatBox> {
201209 // We need only the VerticalDragGestureRecognizer in order to be able to scroll through the messages
202210 Factory (() => VerticalDragGestureRecognizer ()),
203211 },
204- navigationDelegate: widget.navigationDelegate ,
212+ navigationDelegate: _shouldNavigateToUrl ,
205213 );
206214 }
207215
@@ -422,6 +430,25 @@ class ChatBoxState extends State<ChatBox> {
422430 widget.onCustomMessageAction? [action]? .call (MessageActionEvent .fromJson (jsonMessage));
423431 }
424432
433+ FutureOr <NavigationDecision > _shouldNavigateToUrl (
434+ NavigationRequest navigationRequest,
435+ ) {
436+ if (widget.onUrlNavigation != null ) {
437+ final UrlNavigationAction action = widget.onUrlNavigation !(
438+ UrlNavigationRequest (navigationRequest.url),
439+ );
440+
441+ switch (action) {
442+ case UrlNavigationAction .allow:
443+ return NavigationDecision .navigate;
444+ case UrlNavigationAction .deny:
445+ return NavigationDecision .prevent;
446+ }
447+ }
448+
449+ return NavigationDecision .navigate;
450+ }
451+
425452 /// For internal use only. Implementation detail that may change anytime.
426453 ///
427454 /// Return a string with a unique ID
0 commit comments