user22969480
user22969480

Reputation:

The deep link screen is not opening in the Flutter application using GoRouter?

I'm trying to implement deep linking in Flutter using GoRouter. I want to open a specific screen when the user taps on a link. but, it's currently opening the screen within the application from which it's tapped (example if tapped using default messaging, whatsApp) instead of opening it in the actual target application.

I've created/sent a dummy link https://test.com/deep in the default messaging application with a defined host in the AndroidManifest file. When tapped, it opens the screen within the same app, rather than in the Flutter application.

As you can see, when the home button on the Android phone is tapped, the deep link screen is showing in the messaging application instead of in its own Flutter application.

enter image description here

Here is the AndroidManifest.xml-

<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
            <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="http" android:host="hydrocyanic-offende.000webhostapp.com" />
                <data android:scheme="https" />
            </intent-filter>

Here is the goRouter config -

final goRouter = GoRouter(
  initialLocation: '/',
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) => const HomeScreen(),
      routes: [
        GoRoute(
          path: 'deep',
          builder: (context, state) => const DeepLinkScreen(),
        ),
      ],
    ),
  ],
);

When I use the following ADB command, it works as intended by opening the deep link screen in the Flutter application.

adb shell 'am start -a android.intent.action.VIEW \
    -c android.intent.category.BROWSABLE \
    -d "https://test.com/deep"' \
   com.example.app

I'm expecting to open the deep link screen in the Flutter application. I haven't set up the web part where we need to add the assetlinks.json file. Currently, I'm testing with a fake domain name, such as test.com just to see if it's navigate or not.

Upvotes: 0

Views: 377

Answers (1)

Tariqali
Tariqali

Reputation: 389

Open the android folder in your project then AndroidManifest.xml file.inside your activity tag add the below line.It will solve issue open your app in the source app rather than its own window.

 android:launchMode="singleTask"

Upvotes: 0

Related Questions