Skip to content

Unable to navigate with Navigator state after receiving a Deep-link in iOS, Android works fine. #135568

@manthan34

Description

@manthan34

Is there an existing issue for this?

Steps to reproduce

  1. Run the app in iPhone or iOS simulator
  2. Write this link in a chat in iPhone Messages app > nstsaas://com.deeplink.test?error=error
  3. Select the whole link text, tap it once and select the Open Link option
  4. My app will come to foreground but won't navigate to a desire screen.

Expected results

To navigate to a desired screen when app receives a Deep-link.

Actual results

App is not navigating in iPhone where as Android app works as expected.

Code sample

Code sample
import 'package:deeplink/home.dart';
import 'package:deeplink/settings.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
  DeeplinkManager.instance.configureChannel();
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      navigatorKey: NavigationService.navigatorKey,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: HomePage(),
      routes: Routes.routes,
      restorationScopeId: "nst-saas-root",
    );
  }
}

class NavigationService {
  NavigationService._();
  static GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
}

class DeeplinkManager {

  static const channelName = 'com.nst.dltest.deeplink/deeplinkmanager';
  late MethodChannel methodChannel;

  static final DeeplinkManager instance = DeeplinkManager._init();

  DeeplinkManager._init();

  void configureChannel() {
    methodChannel = const MethodChannel(channelName);
    methodChannel.setMethodCallHandler(methodHandler); // set method handler
  }

  Future<void> methodHandler(MethodCall call) async {
    switch (call.method) {
      case "handleDeeplinkData":
        try {
          NavigationService
              .navigatorKey
              .currentState!.pushNamed(Routes.settings,);
        } catch (e) {
          print("Exception: DeeplinkManager > methodHandler: ${e.toString()}");
        }
        break;
      default:
        print("Error: No method handler for: ${call.method}");
    }
  }

}

class Routes {
  Routes._();

  //static variables
  static const String home = '/home';
  static const String settings = '/settings';

  static final routes = <String, WidgetBuilder> {
    home: (BuildContext context) => const HomePage(),
    settings: (BuildContext context) => const SettingsPage(),
  };

}

Screenshots or Video

Screenshots / Video demonstration
android.mov
iPhone.mov

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[!] Flutter (Channel stable, 3.10.5, on macOS 13.3 22E252 darwin-arm64, locale en-IN)
    • Flutter version 3.10.5 on channel stable at /Users/nextsavy/development/flutter
    ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.0.5/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nextsavy/development/flutter. Consider adding
      /Users/nextsavy/development/flutter/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (4 months ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/nextsavy/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.82.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (4 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554                        • android-arm64  • Android 13 (API 33) (emulator)
    • iPhone 14 Pro Max (mobile)  • 733D4B45-2965-4B70-B882-87F8F1CDC0C5 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)             • macos                                • darwin-arm64   • macOS 13.3 22E252 darwin-arm64
    • Chrome (web)                • chrome                               • web-javascript • Google Chrome 117.0.5938.92

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in triagePresently being triaged by the triage teamwaiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions