flutter_web_auth_2 icon indicating copy to clipboard operation
flutter_web_auth_2 copied to clipboard

[Bug]: Android future never return when close web view

Open dagovalsusa opened this issue 1 year ago • 6 comments

Description

Hi,

on Android the authenticate future never return when close web view, I have tried also catching error, but nothing e never return.

Minimal Reproduction

Steps to reproduce the behaviour:

  1. Use the following code:
    try {
      log("HERE bis $result");
      result = await FlutterWebAuth2.authenticate(
          url: url.toString(), callbackUrlScheme: 'myscheme', options: FlutterWebAuth2Options(timeout: 100, preferEphemeral: true, intentFlags: ephemeralIntentFlags));
      log("HERE tris $result");
    } catch (e, s) {
      log("HERE catch $result");
      FirebaseCrashlytics.instance.recordError(e, s);
      PlatformException exc = (e as PlatformException);
      if (exc.code == "CANCELED") return;
    }
    

Exception or Error

no error logs

Expected Behaviour

I will expected a null value, or a exception

Screenshots

No response

Additional context

No response

Device

Android Emulator Pixel 4

OS

Android

Browser

Chrome

Flutter version

3.16

flutter_web_auth_2 version

3.0.4

Checklist

  • [X] I have read and followed the entire troubleshooting guide and it has not provided the solution I need.
  • [X] I have provided all the information I can.

dagovalsusa avatar Dec 05 '23 15:12 dagovalsusa

As described in the documentation, timeout does not work on Android. Did you follow all the setup steps as described here?

ThexXTURBOXx avatar Dec 05 '23 15:12 ThexXTURBOXx

Yes, I have setup all steps, also on AndroidManifest.

<application
        android:label="------"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:usesCleartextTraffic="false"
        android:debuggable="false"
        android:allowBackup="false">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https" />
                <data android:host="my host" />
            </intent-filter>
        </activity>

        <activity
        android:name="com.linusu.flutter_web_auth_2.CallbackActivity"
        android:exported="true">
            <intent-filter android:label="flutter_web_auth_2">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="myscheme" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.yalantis.ucrop.UCropActivity"
            android:screenOrientation="portrait"
            android:exported="false"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>


        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>

dagovalsusa avatar Dec 05 '23 15:12 dagovalsusa

webview disappear when I press recent app or home button in android device. final result = await FlutterWebAuth2.authenticate( url: url, callbackUrlScheme: Constants.callbackUrlScheme, options: const FlutterWebAuth2Options(intentFlags: ephemeralIntentFlags), );

tinu2610 avatar Dec 11 '23 12:12 tinu2610

@tinu2610 You are using ephemeralIntentFlags. This is exactly the intended behaviour when using those.

ThexXTURBOXx avatar Dec 11 '23 13:12 ThexXTURBOXx

@ThexXTURBOXx then how can I avoid that situation. I don't want multiple instances of webview. if i'm using ephemeralIntentFlags then after switching my original app with another app the WebView will completely disappear.

As linkedln using within app webview can we use same as from this package.

tinu2610 avatar Dec 12 '23 04:12 tinu2610

This is a question you should be asking on Stack Overflow. Please don't hijack issues on GitHub for questions like these. This makes it hard for maintainers to keep track of real issues within their packages.

ThexXTURBOXx avatar Dec 12 '23 06:12 ThexXTURBOXx