@@ -89,6 +89,7 @@ class ChatBox extends StatefulWidget {
89
89
final TranslationToggledHandler ? onTranslationToggled;
90
90
final LoadingStateHandler ? onLoadingStateChanged;
91
91
final Map <String , MessageActionHandler >? onCustomMessageAction;
92
+ final NavigationHandler ? onUrlNavigation;
92
93
93
94
const ChatBox ({
94
95
Key ? key,
@@ -107,6 +108,7 @@ class ChatBox extends StatefulWidget {
107
108
this .onTranslationToggled,
108
109
this .onLoadingStateChanged,
109
110
this .onCustomMessageAction,
111
+ this .onUrlNavigation,
110
112
}) : super (key: key);
111
113
112
114
@override
@@ -237,6 +239,13 @@ class ChatBoxState extends State<ChatBox> {
237
239
},
238
240
shouldOverrideUrlLoading: (InAppWebViewController controller, NavigationAction navigationAction) async {
239
241
if (navigationAction.navigationType == NavigationType .LINK_ACTIVATED ) {
242
+ if (widget.onUrlNavigation != null ) {
243
+ // The onUrlNavigation function has been defined, so let's see if we should open the browser or not
244
+ if (widget.onUrlNavigation !(UrlNavigationRequest (navigationAction.request.url! .rawValue)) == UrlNavigationAction .deny) {
245
+ return NavigationActionPolicy .CANCEL ;
246
+ }
247
+ }
248
+
240
249
if (await launchUrl (navigationAction.request.url! )) {
241
250
// We launched the browser, so we don't navigate to the URL in the WebView
242
251
return NavigationActionPolicy .CANCEL ;
@@ -245,6 +254,7 @@ class ChatBoxState extends State<ChatBox> {
245
254
return NavigationActionPolicy .ALLOW ;
246
255
}
247
256
}
257
+
248
258
return NavigationActionPolicy .ALLOW ;
249
259
},
250
260
);
0 commit comments