Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/src/chatbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -107,6 +108,7 @@ class ChatBox extends StatefulWidget {
this.onTranslationToggled,
this.onLoadingStateChanged,
this.onCustomMessageAction,
this.onUrlNavigation,
}) : super(key: key);

@override
Expand Down Expand Up @@ -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;
Expand All @@ -245,6 +254,7 @@ class ChatBoxState extends State<ChatBox> {
return NavigationActionPolicy.ALLOW;
}
}

return NavigationActionPolicy.ALLOW;
},
);
Expand Down