Skip to content

Commit bbdc8d2

Browse files
authored
Merge pull request #30 from talkjs/feat/navigation-delegate
Re-enabled the onUrlNavigation callback on the ChatBox
2 parents 740671b + a9d0cb5 commit bbdc8d2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/src/chatbox.dart

+10
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class ChatBox extends StatefulWidget {
8989
final TranslationToggledHandler? onTranslationToggled;
9090
final LoadingStateHandler? onLoadingStateChanged;
9191
final Map<String, MessageActionHandler>? onCustomMessageAction;
92+
final NavigationHandler? onUrlNavigation;
9293

9394
const ChatBox({
9495
Key? key,
@@ -107,6 +108,7 @@ class ChatBox extends StatefulWidget {
107108
this.onTranslationToggled,
108109
this.onLoadingStateChanged,
109110
this.onCustomMessageAction,
111+
this.onUrlNavigation,
110112
}) : super(key: key);
111113

112114
@override
@@ -237,6 +239,13 @@ class ChatBoxState extends State<ChatBox> {
237239
},
238240
shouldOverrideUrlLoading: (InAppWebViewController controller, NavigationAction navigationAction) async {
239241
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+
240249
if (await launchUrl(navigationAction.request.url!)) {
241250
// We launched the browser, so we don't navigate to the URL in the WebView
242251
return NavigationActionPolicy.CANCEL;
@@ -245,6 +254,7 @@ class ChatBoxState extends State<ChatBox> {
245254
return NavigationActionPolicy.ALLOW;
246255
}
247256
}
257+
248258
return NavigationActionPolicy.ALLOW;
249259
},
250260
);

0 commit comments

Comments
 (0)