Skip to content

Different deeplinking url between onGenerateInitialRoutes and onGenerateRoute #161867

Open

Description

@julien4215

Steps to reproduce

  1. Run the code sample
  2. Run this command to test deeplink.
adb shell 'am start -a android.intent.action.VIEW \
  -c android.intent.category.BROWSABLE \
  -d "https://example.com/test"' \
  com.example.test
  1. Note the printed value of onGenerateRoute method
  2. Stop the app
  3. Run flutter logs
  4. Run this command again
adb shell 'am start -a android.intent.action.VIEW \
  -c android.intent.category.BROWSABLE \
  -d "https://example.com/test"' \
  com.example.test
  1. Note the printed value by onGenerateInitialRoutes method

Expected results

The two printed values should be the same

Actual results

The two values are different. onGenerateInitialRoutes keeps all the url https://example.com/test while onGenerateRoute keeps only the path /test.

Code sample

main.dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    final route = MaterialPageRoute(builder: (context) => Text('Page'));
    return MaterialApp(
      title: 'Example',
      onGenerateRoute: (settings) {
        print(settings.name);
        return route;
      },
      onGenerateInitialRoutes: (intitialRoute) {
        print(intitialRoute);
        return [route];
      },
    );
  }
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application
        android:label="test"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:taskAffinity=""
            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" android:host="example.com" />
            </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" />
    </application>
    <!-- Required to query activities that can process text, see:
         https://developer.android.com/training/package-visibility and
         https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.

         In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
    <queries>
        <intent>
            <action android:name="android.intent.action.PROCESS_TEXT"/>
            <data android:mimeType="text/plain"/>
        </intent>
    </queries>
</manifest>

Flutter Version

Flutter version 3.28.0-0.1.pre on channel beta

Activity

  1. darshankawar commented on Jan 20, 2025

    @darshankawar
    Member

    @julien4215
    Please check the behavior described for https://api.flutter.dev/flutter/material/MaterialApp/onGenerateRoute.html to see if it helps further in your case as why it could be different behavior.

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 20, 2025
  3. julien4215 commented on Jan 20, 2025

    @julien4215
    Author

    @darshankawar
    It doesn't explain the different behavior. I think that initialRoute should only be the path without the scheme and the base url or else mention in the documentation that there is this different behavior when using a deeplink.

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 20, 2025
  5. darshankawar commented on Jan 21, 2025

    @darshankawar
    Member

    Thanks for the update. I do see the same behavior upon following the details as provided.

    stable : 3.27.2
    master : 3.28.0-2.0.pre.38786
    
  6. added
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: routesNavigator, Router, and related APIs.
    and removed
    in triagePresently being triaged by the triage team
    on Jan 21, 2025
  7. goderbauer commented on Jan 21, 2025

    @goderbauer
    Member

    @chunhtai I think this is expected behavior. Can you confirm?

  8. added
    P3Issues that are less important to the Flutter project
    on Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectf: routesNavigator, Router, and related APIs.found in release: 3.27Found to occur in 3.27found in release: 3.28Found to occur in 3.28frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions