问题描述
我正在尝试通过遵循FilledStacks上传的视频来实现堆叠式体系结构。 我在使用可注射pub软件包时遇到问题 https://pub.dev/packages/injectable
我的locator.dart类代码如下
import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';
final locator = GetIt.instance;
@injectableInit
void setupLocator() => $initGetIt(locator);
$initGetIt(locator)
上出现此错误
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
即使我按照软件包文档中显示的方式实施软件包
https://www.youtube.com/watch?v=DO8le1W_HqQ&t=914s
解决方法
- 在dev_dependencies中添加pubspec.yaml:
injectable_generator:
- 运行
flutter packages pub run build_runner build
- 从生成的文件中导入
$initGetIt