如何解决使用可注射pub包时未定义函数'$ initGetIt'
我正在尝试通过遵循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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。