skip to Main Content

I am currently using Navigation 1.0 and want to add deep links within the current navigation setup. I am aware that it is simple to add deep links with Navigation 2.0 using packages like go_router. However, I want to implement deep links without relying on any additional packages such as go_router, uni_links, or Firebase.

I have read a couple of articles where they explain the process using the mentioned packages, I prefer not to use them. i’m expecting to handle deep-links the current navigation 1.0 setup.

2

Answers


  1. It is possible to handle deep-links without using any package. You need to write some native code to handle it though, That’s exactly why we use packages like uni_links or app_links.

    Although, this link is mentioned in official flutter docs for deep-linking using native code (by writing a native plugin): Deep Links and Flutter applications. How to handle them properly

    Login or Signup to reply.
  2. Actually it’s possible without writing a native code. Here is an example:

    First configure the project for deep linking. Add schemas in the manifest file

    // AndroidManifest.xml
    
    <intent-filter android:autoVerify="false">
        <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="test.com" />
        <data android:scheme="https" />
        <data
            android:host="test.com"
            android:scheme="myapp" />
    </intent-filter>
    

    Then add onGenerateRoute parameter to the MaterialApp widget

    // main.dart
    
    onGenerateRoute: (settings) {
      switch (settings.name) {
        case '/':
          return MaterialPageRoute(builder: (_) => HomePage());
        case '/login':
          return MaterialPageRoute(builder: (_) => LoginPage());
        case '/deep':
          return MaterialPageRoute(builder: (_) => DeepPage());
        default:
          return MaterialPageRoute(builder: (_) => HomePage());
      }
    },
    

    Now, by opening this link the app is opened with the route /deep (DeepPage):
    myapp://test.com/deep

    Note: This example contains configuration for basic testing of a deep link. For the correct configuration for your project, and using universal app links on both android and iOS, follow instructions on this page (except the GoRouter part).

    And here is the example project

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search