Flutter:在我的 AutoRoute 库的 deeplinkBuilder 中,我的深层链接始终是“/”

问题描述 投票:0回答:1

我在 Flutter 上的深度链接问题上被困了几天。

我使用 Flutter“auto_route”库,它使我可以通过 router.config() 中的“deeplinkBuilder”直接访问深层链接。

配置 Android 部分(用于测试目的)并在 AndroidManifest.xml 中添加意图过滤器后,每次打开深层链接时,deeplinkBuilder 都不会检测到我的链接并告诉我它等于“/”。

这是我的深层链接: 方案://主/仪表板

这是我的 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,
          );

其中 deepLink.path 始终为“/”而不是“/main/dashboard”

这里还有我的 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>

其中“${deeplinkScheme}”在 build.gradle 中定义,其方案与我的深层链接相同。

因此深层链接确实打开了应用程序,但从未在其中检测到。

我是否忘记发起某件事?

如何让我的应用程序识别其内部的深层链接?

小记:

我只需要deeplink,不需要AppLink(通用链接)。 我的深层链接不是“http”链接。只是一个简单的移动平台深度链接。

另外,我正在研究 auto_route 版本:^7.8.4

欢迎任何帮助。

提前致谢:)

我也尝试过: 我在 iOS 上进行了测试,通过在 Info.plist 文件中提供方案,应用程序可以打开它,但打开时也不会检测到深层链接。

flutter deep-linking android-deep-link auto-route flutter-deep-link
1个回答
0
投票

来自 flutter 文档

对于 Android,您需要修改 AndroidManifest.xml 文件。在主要活动的标签内添加以下元数据:

<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />

参考:为 Android 设置应用程序链接 - Flutter

对于 ios,要在 Flutter 应用程序中启用深度链接,您需要将以下条目添加到 Info.plist 文件中:

<key>FlutterDeepLinkingEnabled</key>
<true/>

参考:为 iOS 设置通用链接 - flutter

© www.soinside.com 2019 - 2024. All rights reserved.