0

When using url_launcher with following code, the token is not taken into account in iOS and Android simulators. It opens the url starting with login page, while with the 'Authorization' header and token it should already be considered a logged in user.

The same code works on Flutter Web in all modes (inAppWebView, inAppBrowserView, externalApplication), and the page opens with the user already logged in.

Future<void> _launchInWebView(Uri url) async {
    try {
      await launchUrl(url, mode: LaunchMode.inAppWebView,
          webViewConfiguration: WebViewConfiguration(
              headers: EndUserApiRequest.ssoHeaders
          ));
    } on Exception catch (e) {
      if (kDebugMode) print(e.toString());
    }
  }

As you can see in this screenshot, the token headers are included in the call.

Token header is properly set

1 Answer 1

1

Try using InAppWebView instead and see if the problem is still there. InAppWebView in my experience has been more reliable

`

Future<void> _launchInAppWebView(Uri url) async {
  try {
    InAppWebViewController webViewController;
    await InAppWebView(
      initialUrlRequest: URLRequest(
        url: url,
        headers: EndUserApiRequest.ssoHeaders,
      ),
      onWebViewCreated: (controller) {
        webViewController = controller;
      },
    ).launch(context);
  } on Exception catch (e) {
    if (kDebugMode) print(e.toString());
  }
}`
Sign up to request clarification or add additional context in comments.

3 Comments

That's what I used, see code and screenshot.
Didn't specify enough I meant use that instead of url_launcher at the start. Something like this should give you more control over how web view: Future<void> _launchInAppWebView(Uri url) async { try { InAppWebViewController webViewController; await InAppWebView( initialUrlRequest: URLRequest( url: url, headers: EndUserApiRequest.ssoHeaders, ), onWebViewCreated: (controller) { webViewController = controller; }, ).launch(context); } on Exception catch (e) { if (kDebugMode) print(e.toString()); } }
Thank you for pointing me to this package, I was looking for another package to test and this flutter_inappwebview seems good. Unfortunately your code doesn't work anymore with the latest version (6.0.0), but I will find out how to use the package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.