最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

flutter - Is there any method or flag to determine app is opened by deeplink? - Stack Overflow

matteradmin5PV0评论

Deeplinks in my flutter app are set up using standard mechanism /ui/navigation/deep-linking Everything works fine when app is already ruuning, I can navigate to any page. But when app is in closed state, I need to check some conditions first and possibly navigate to other pages, so I need to determine whether app is called by deeplink, and can't find any method of flag assosiated with that.

For example, I have Firebase push notifications set up and there is special method getInitialMessage(), which receives message if we open app via push (not tapping icon). Is there something similar for deeplinks?

my simplified onGenerateRoute method:

Route<dynamic> onGenerateRoute(RouteSettings settings) {
    WidgetBuilder builder;
    switch (settings.name) {
      case '/auth':
        builder = (BuildContext context) => AuthPage();
        break;
      case '/code':
        builder = (BuildContext context) => CodePage();
        break;
      case '/welcome':
        builder = (BuildContext context) => WelcomePage();
    }
    return PageRoute(
      builder: (context) => builder(context),
      settings: settings,
    );

Deeplinks in my flutter app are set up using standard mechanism https://docs.flutter.dev/ui/navigation/deep-linking Everything works fine when app is already ruuning, I can navigate to any page. But when app is in closed state, I need to check some conditions first and possibly navigate to other pages, so I need to determine whether app is called by deeplink, and can't find any method of flag assosiated with that.

For example, I have Firebase push notifications set up and there is special method getInitialMessage(), which receives message if we open app via push (not tapping icon). Is there something similar for deeplinks?

my simplified onGenerateRoute method:

Route<dynamic> onGenerateRoute(RouteSettings settings) {
    WidgetBuilder builder;
    switch (settings.name) {
      case '/auth':
        builder = (BuildContext context) => AuthPage();
        break;
      case '/code':
        builder = (BuildContext context) => CodePage();
        break;
      case '/welcome':
        builder = (BuildContext context) => WelcomePage();
    }
    return PageRoute(
      builder: (context) => builder(context),
      settings: settings,
    );
Share Improve this question asked Nov 18, 2024 at 12:38 adminantadminant 111 bronze badge 2
  • You have to save the event that opened the deep link yourself, as every company app does – Nguyễn Minh Khoa Commented Nov 19, 2024 at 5:40
  • @NguyễnMinhKhoa Could you please explain in detail? What I need to save? There is no any information that someone came to app via deep link. – adminant Commented Nov 19, 2024 at 10:04
Add a comment  | 

1 Answer 1

Reset to default 0

You can use the package AppLinks from pub.dev and in that you have methods which will be useful in identifying whether you've opened a deeplink or not. with a little customization, you'll be able determine whether you've opened the app from deeplink or not.

find the example here at https://pub.dev/packages/app_links/example

Navigation Observer will help you in identifying the Navigation stack and hence the navigations.

Post a comment

comment list (0)

  1. No comments so far