Flutter : My deeplink is always "/" in my deeplinkBuilder of AutoRoute library

35 Views Asked by At

I've been stuck for a few days on the subject of deeplinks on Flutter.

I use the Flutter "auto_route" library, which gives me direct access to deeplinks via its "deeplinkBuilder" in router.config().

After configuring the Android part (for testing purposes) and adding the intent-filter in the AndroidManifest.xml, each time a deeplink is opened, the deeplinkBuilder doesn't detect my link and tells me it's equal to "/".

Here my deeplink : scheme://main/dashboard

Here my MaterialApp.router :

return MaterialApp.router(
            routerConfig: _appRouter.config(
              deepLinkBuilder: (deepLink) {
                if (deepLink.path.contains('/main')) {
                  return deepLink;
                } else {
                  return DeepLink.defaultPath;
                }
              },
            ),
            title: 'App name',
            localizationsDelegates: const [
              AppLocalizations.delegate,
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
              GlobalCupertinoLocalizations.delegate,
            ],
            supportedLocales: const [
              Locale('fr', 'FR'),
            ],
            theme: AppTheme.lightThemeData,
            darkTheme: AppTheme.darkThemeData,
            themeMode: state.themeMode,
          );

Where deepLink.path is always as "/" instead of "/main/dashboard"

Also here my AndroidManifest.xml :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example">

    <!-- Android 11+ -->
    <uses-feature android:name="android.hardware.camera" />
    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data
                android:host="*"
                android:scheme="https" />
        </intent>
    </queries>

    <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
    <uses-permission android:name="android.permission.ACTION_MANAGE_WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:usesCleartextTraffic="true">
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:exported="true"
            android:hardwareAccelerated="true"
            android:launchMode="singleTask"
            android:networkSecurityConfig="@xml/network_security_config"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme"
            android:windowSoftInputMode="adjustResize">
            <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="${deeplinkScheme}" />
            </intent-filter>
        </activity>
        <!-- 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" />
        <meta-data
            android:name="flutter_deeplinking_enabled"
            android:value="true" />
    </application>
</manifest>

Where "${deeplinkScheme}" is defined in build.gradle with the same scheme than my deeplink.

So the deeplink does open the application, but is never detected inside it.

Did I forget to initiate something?

How can I get my application to recognize my deeplink inside itself?

Little note:

I only need deeplink and not AppLink (Universal link). My deeplink is not an "http" link. Just a simple deeplink for mobile platform.

Also, I work on version auto_route: ^7.8.4

Any help is welcome.

Thanks in advance :)

What I tried too : I tested on iOS by giving the scheme in the Info.plist file, the application can open it but doesn't detect the deeplink on opening either.

0

There are 0 best solutions below