我想在生成器代码上放置断点,但是我不知道如何在调试模式下运行命令。
我使用source_gen
和build_runner
class MyGenerator extends GeneratorForAnnotation<Todo> {
@override
FutureOr<String> generateForAnnotatedElement(
Element element, ConstantReader annotation, BuildStep buildStep) {
return "// Hey! Annotation found!";
}
}
答案 0 :(得分:3)
1)运行逗号@Override
protected void onDestroy() {
/// do smthng
super.onDestroy();
}
2)将flutter packages pub run build_runner build
复制到项目的根文件夹
答案 1 :(得分:0)
Ivan 的回答对我有用,但是每次我更改使用注释的文件时 - 输出的构建过程:
[SEVERE] Terminating builds due to build script update
[INFO] Terminating. No further builds will be scheduled
然后将构建脚本本身从 build.dart
重命名为 build.dart.cached
,然后以代码 75 退出。
在深入研究 build_runner
代码后,我发现可以通过使用以下程序参数来缓解这种行为:
serve --skip-build-script-check
(即,而不是像伊万建议的那样只是 serve
)。
可能会有一些负面的后果;在 build_runner
源代码中,在 options.dart
中,我看到了:
// For testing only, skips the build script updates check.
bool skipBuildScriptCheck;