flutter_webview_plugin icon indicating copy to clipboard operation
flutter_webview_plugin copied to clipboard

onUrlChanged.listen never called on iOS

Open brunovsiqueira opened this issue 6 years ago • 4 comments

System info

Issue occurs on: iOS Plugin version: xxx

#Problem

I am using onUrlChanged.listen in order to get the code of OAuth2 authentication. I get this code by listening to url changes, and it works fine on Android. When I launch it in iOS, I get a blank white screen. When I try to debug, I see that onUrlChanged.listen callback is never being called.

Here is my code: void main() { WidgetsFlutterBinding.ensureInitialized(); LoginController _loginController = new LoginController(); _loginController.getCodeWebView().then((FlutterWebviewPlugin flutterWebView) { //deal here with webview and token request flutterWebView.onUrlChanged.listen((String url) async { if (url.length > 25) { int endIndex = url.indexOf("&state"); if (url.contains("code=")) { String code = url.substring( url.indexOf('code') + 5, endIndex); //with "http://localhost:4200/ flutterWebView.close(); String accessToken = await _loginController.getAccessToken(code); _loginController.decodeJwtAndPopulateUser(accessToken); //Now that we have the token, we can instantiate layout with async calls that depends on token runApp( AppContainer(accessToken) ); } } }); }); }

Can anyone help me please? I am struggling with it. I don't know if its a bug. I am testing it in iOS 13.3 and I already added the info.plist things to support webview_plugin:

<dict> <key>NSAllowsArbitraryLoads</key> <true/> <key>NSAllowsArbitraryLoadsInWebContent</key> <true/> </dict>

brunovsiqueira avatar Feb 12 '20 14:02 brunovsiqueira

@davik4life @charafau Can you guys help me please?

brunovsiqueira avatar Feb 12 '20 14:02 brunovsiqueira

I would suggest you ask this in stackoverflow because I don't think this is a support forum...BUT you need to call flutterWebView.launch() or similar (check examples for better understanding) before any listening can happen.

So this is not a bug. You aren't just using it correctly.

villematti avatar Mar 09 '20 17:03 villematti

Getting the same here.. but if using the example app it works

oliverbytes avatar Mar 28 '20 08:03 oliverbytes

@villematti So Sorry, I just saw your message now. Were you able to find a fix? Pls let us know, Thanks.

davik4life avatar Jul 17 '20 21:07 davik4life