Object/factory with type NavigationService is not registered inside GetIt

Mad*_*ami 5 dart flutter flutter-navigation

This error keeps coming in my development

Debug Console

[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: 'package:get_it/get_it_impl.dart': Failed assertion: line 312 pos 7: 'instanceFactory != null': Object/factory with  type NavigationService is not registered inside GetIt.
E/flutter (27190): (Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;
E/flutter (27190): Did you forget to register it?)

Run Code Online (Sandbox Code Playgroud)

This is the navigator service file in which the navigation service as well as getit is initialised

navigation_service.dart

GetIt locator = GetIt.instance;

setupLocator() {
  locator.registerLazySingleton(() => NavigationService());
}

class NavigationService {
  final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
  Future<dynamic> navigateTo(routeName) {
    return navigatorKey.currentState.pushReplacementNamed(routeName);
  }

  goBack() {
    return navigatorKey.currentState.pop();
  }
}


Run Code Online (Sandbox Code Playgroud)

dynamic_link_service.dart

.
.
.
#some code

final NavigationService _navigationService = locator<NavigationService>();

if (deepLink != null) {
      // print('_handleDeepLink | deepLink: $deepLink');
      UserDataProvider().setReferralData(deepLink);
      _navigationService.navigateTo(ReferralSignupPage.routeName);
    }
.
.
.

Run Code Online (Sandbox Code Playgroud)

main.dart

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await setupLocator();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        home:
        .
        .
        .
        routes: {
          ReferralSignupPage.routeName: (ctx) => ReferralSignupPage(),
        },
        navigatorKey: locator<NavigationService>().navigatorKey,
      );
}
Run Code Online (Sandbox Code Playgroud)

This error keeps coming even after having tried all the possible solutions provided in other questions Please help me out of this.

Regards

Mar*_*ijn 0

这里只是一个猜测,但语法不是:

final service = locator.get<NavigationService>();
Run Code Online (Sandbox Code Playgroud)

您也可能需要在注册服务时提供通用参数。