Search code examples
intellij-ideaflutterdartbuild-runner

How run flutter 'packages pub run build_runner build' with debug mode in intellij idea?


I want to put break point on my generator code, but I don't know how to run the command on the debug mode.

I wrote generator using source_gen and build_runner

class MyGenerator extends GeneratorForAnnotation<Todo> {
  @override
  FutureOr<String> generateForAnnotatedElement(
      Element element, ConstantReader annotation, BuildStep buildStep) {
    return "// Hey! Annotation found!";
  }
}

Solution

    1. run commad flutter packages pub run build_runner build*

    2. copy build.dart to root folder of project

    enter image description here

    1. add new run configuration enter image description here
    2. run debug, now you can debug your code generator!

    * the packages is optional, you can just run flutter pub run build_runner build