The function '$initGetIt' isn't defined while using injectable pub package

Viewed 1347

I am trying to implement stacked architecture by following this video uploaded by FilledStacks. I encountered a problem while using injectable pub package https://pub.dev/packages/injectable

My locator.dart class code is as follow

import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';

final locator = GetIt.instance;

@injectableInit
void setupLocator() => $initGetIt(locator);

on $initGetIt(locator) I'm getting this error

The function '$initGetIt' isn't defined.
Try importing the library that defines '$initGetIt', correcting the name to the name of an existing function, or defining a function named 

Even though I am implementing package the way it is shown in the package documentation

https://www.youtube.com/watch?v=DO8le1W_HqQ&t=914s

1 Answers
  1. Add in pubspec.yaml in dev_dependencies: injectable_generator:
  2. Run flutter packages pub run build_runner build
  3. Import $initGetIt from generated file
Related