admin管理员组

文章数量:1435823

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.

本文标签: flutterIs there any method or flag to determine app is opened by deeplinkStack Overflow