diff --git a/lib/src/chatbox.dart b/lib/src/chatbox.dart index 19b9da7..c14c04d 100644 --- a/lib/src/chatbox.dart +++ b/lib/src/chatbox.dart @@ -89,6 +89,7 @@ class ChatBox extends StatefulWidget { final TranslationToggledHandler? onTranslationToggled; final LoadingStateHandler? onLoadingStateChanged; final Map<String, MessageActionHandler>? onCustomMessageAction; + final NavigationHandler? onUrlNavigation; const ChatBox({ Key? key, @@ -107,6 +108,7 @@ class ChatBox extends StatefulWidget { this.onTranslationToggled, this.onLoadingStateChanged, this.onCustomMessageAction, + this.onUrlNavigation, }) : super(key: key); @override @@ -237,6 +239,13 @@ class ChatBoxState extends State<ChatBox> { }, shouldOverrideUrlLoading: (InAppWebViewController controller, NavigationAction navigationAction) async { if (navigationAction.navigationType == NavigationType.LINK_ACTIVATED) { + if (widget.onUrlNavigation != null) { + // The onUrlNavigation function has been defined, so let's see if we should open the browser or not + if (widget.onUrlNavigation!(UrlNavigationRequest(navigationAction.request.url!.rawValue)) == UrlNavigationAction.deny) { + return NavigationActionPolicy.CANCEL; + } + } + if (await launchUrl(navigationAction.request.url!)) { // We launched the browser, so we don't navigate to the URL in the WebView return NavigationActionPolicy.CANCEL; @@ -245,6 +254,7 @@ class ChatBoxState extends State<ChatBox> { return NavigationActionPolicy.ALLOW; } } + return NavigationActionPolicy.ALLOW; }, );