@@ -55,8 +55,6 @@ class MessageActionEvent {
5555 message = Message .fromJson (json['message' ]);
5656}
5757
58- enum UrlNavigationAction { allow, deny }
59-
6058class UrlNavigationRequest {
6159 final String url;
6260
@@ -65,6 +63,8 @@ class UrlNavigationRequest {
6563 );
6664}
6765
66+ enum UrlNavigationAction { deny, allow }
67+
6868/// A messaging UI for just a single conversation.
6969///
7070/// Create a Chatbox through [Session.createChatbox] and then call [mount] to show it.
@@ -206,6 +206,7 @@ class ChatBoxState extends State<ChatBox> {
206206 initialSettings: InAppWebViewSettings (
207207 useHybridComposition: true ,
208208 disableInputAccessoryView: true ,
209+ useShouldOverrideUrlLoading: true ,
209210 ),
210211 onWebViewCreated: _onWebViewCreated,
211212 onLoadStop: _onLoadStop,
@@ -234,7 +235,7 @@ class ChatBoxState extends State<ChatBox> {
234235 // We need only the VerticalDragGestureRecognizer in order to be able to scroll through the messages
235236 Factory (() => VerticalDragGestureRecognizer ()),
236237 },
237- navigationDelegate : _shouldNavigateToUrl,
238+ shouldOverrideUrlLoading : _shouldNavigateToUrl,
238239 );
239240 }
240241
@@ -391,10 +392,10 @@ class ChatBoxState extends State<ChatBox> {
391392 controller.addJavaScriptHandler (handlerName: 'JSCCustomMessageAction' , callback: _jscCustomMessageAction);
392393
393394 String htmlData = await rootBundle.loadString ('packages/talkjs_flutter/assets/index.html' );
394- controller.loadData (data: htmlData, baseUrl: Uri . parse ("https://app.talkjs.com" ));
395+ controller.loadData (data: htmlData, baseUrl: WebUri ("https://app.talkjs.com" ));
395396 }
396397
397- void _onLoadStop (InAppWebViewController controller, Uri ? url) async {
398+ void _onLoadStop (InAppWebViewController controller, WebUri ? url) async {
398399 if (kDebugMode) {
399400 print ('📗 chatbox._onLoadStop ($url )' );
400401 }
@@ -465,23 +466,24 @@ class ChatBoxState extends State<ChatBox> {
465466 widget.onCustomMessageAction? [action]? .call (MessageActionEvent .fromJson (jsonMessage));
466467 }
467468
468- FutureOr <NavigationDecision > _shouldNavigateToUrl (
469- NavigationRequest navigationRequest,
470- ) {
469+ Future <NavigationActionPolicy ?> _shouldNavigateToUrl (
470+ InAppWebViewController controller,
471+ NavigationAction navigationAction,
472+ ) async {
471473 if (widget.onUrlNavigation != null ) {
472474 final UrlNavigationAction action = widget.onUrlNavigation !(
473- UrlNavigationRequest (navigationRequest. url),
475+ UrlNavigationRequest (navigationAction.request. url! .rawValue ),
474476 );
475477
476478 switch (action) {
477479 case UrlNavigationAction .allow:
478- return NavigationDecision .navigate ;
480+ return NavigationActionPolicy . ALLOW ;
479481 case UrlNavigationAction .deny:
480- return NavigationDecision .prevent ;
482+ return NavigationActionPolicy . CANCEL ;
481483 }
482484 }
483485
484- return NavigationDecision .navigate ;
486+ return NavigationActionPolicy . ALLOW ;
485487 }
486488
487489 /// For internal use only. Implementation detail that may change anytime.
0 commit comments