I'm working with webview_flutter in order to Auth my users through Cognito's auth endpoint.
This is my WebView:
return WebView(
initialUrl: url,
userAgent: 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) ' +
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Mobile Safari/537.36',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_webViewController.complete(webViewController);
},
navigationDelegate: (NavigationRequest request) async {
print("Current url : ${request.url}");
if (request.url.startsWith('myapp://?code=')) {
print("Preventing navigation");
return NavigationDecision.prevent;
}
print("Navigated to url");
},
onPageFinished: (String url) async {
print("onPageFinished with url: $url");
if (url.startsWith('myapp://?code=')) {
code = url.substring('myapp://?code='.length).split('#')[0];
final Map<String, String> userData = await globals.cognitoClient
.signUserInWithThirdPartyAuthCode(code);
final UserModel user = await globals.appSyncClient.fetchMyProfile();
userState.user = user;
if (user.username != null && user.username != '') {
Navigator.pushNamedAndRemoveUntil(
context, '/home', (Route<dynamic> route) => false);
} else {
Navigator.pushReplacement(context, MaterialPageRoute<dynamic>(
builder: (BuildContext context) {
return TpSignUpPage(
name: userData['name'],
surname: userData['surname'],
tptype: widget.tpType,
);
},
));
}
}
},
gestureNavigationEnabled: true,
);
Preventing navigation when the url contains my auth code allows me to do the magic inside onPageFinished and on Android everything works fine.
On the other hand, on iOS the onPageFinished callback never gets called. The print never shows up in the console and the navigation stops at the auth code without nothing getting done. I've even checked if requests are for the main frame, they are.
This is what i get:
flutter: Current url : https://xxxxxxxxxxx.auth.eu-central-1.amazoncognito.com/oauth2/authorize?identity_provider=Facebook&redirect_uri=myapp://&response_type=CODE&client_id=xxxxxxxxxxxxxxxxxxxxxx&scope=email%20openid%20profile%20aws.cognito.signin.user.admin
flutter: Navigated to url
flutter: Current url : myapp://?code=4xxxxxxx-xxx8-xxxx-a88a-7xxxxxxxxx3
flutter: Preventing navigation
Whereas after every navigation onPageFinished's supposed to be called.
I really don't know how or why this might happen; I've searched through many issues and my current Info.plist contains :
<key>io.flutter.embedded_views_preview</key>
<true/>
and this is my flutter doctor -v:
[✓] Flutter (Channel stable, 1.22.5, on Mac OS X 10.15.7 19H2 darwin-x64, locale it-IT)
• Flutter version 1.22.5 at /usr/local/Caskroom/flutter/1.22.0/flutter
• Framework revision 7891006299 (7 weeks ago), 2020-12-10 11:54:40 -0800
• Engine revision ae90085a84
• Dart version 2.10.4
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/sabe/Library/Android/sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.2, Build version 12B45b
• CocoaPods version 1.9.3
[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 50.0.1
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[!] IntelliJ IDEA Ultimate Edition (version 2019.1.3)
• IntelliJ at /Applications/IntelliJ IDEA.app
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• For information about installing plugins, see
https://flutter.dev/intellij-setup/#installing-the-plugins
[✓] VS Code (version 1.52.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.18.1
[✓] Connected device (1 available)
• iPhone 12 Pro Max (mobile) • 83C45AD2-68CE-4260-B932-57C4B5B861D4 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-14-2 (simulator)
! Doctor found issues in 1 category.
(I don't use IntelliJ anymore so w/ever)
Steps to Reproduce : I'm assuming just run a webview on ios having onPageFinished populated ?
What could be causing this issue? Pls send help
I'm working with webview_flutter in order to Auth my users through Cognito's auth endpoint.
This is my WebView:
Preventing navigation when the url contains my auth code allows me to do the magic inside onPageFinished and on Android everything works fine.
On the other hand, on iOS the onPageFinished callback never gets called. The print never shows up in the console and the navigation stops at the auth code without nothing getting done. I've even checked if requests are for the main frame, they are.
This is what i get:
Whereas after every navigation onPageFinished's supposed to be called.
I really don't know how or why this might happen; I've searched through many issues and my current Info.plist contains :
and this is my flutter doctor -v:
(I don't use IntelliJ anymore so w/ever)
Steps to Reproduce : I'm assuming just run a webview on ios having onPageFinished populated ?
What could be causing this issue? Pls send help