flutterdartbuild-runner

How to use Flutter with build_runner?


I'm developing a build_runner plugin that captures const widgets and converts them to images. The process should be triggered by running flutter packages pub run build_runner build to create snapshots. However, I'm encountering issues importing Flutter within the build_runner context. When I try to import Flutter, it results in numerous reference errors.

I'm puzzled because if the command line can't use Flutter, how does flutter test work? It seems there should be a way to execute Flutter from the command line.

My questions are:

  1. Is it possible to use Flutter within a build_runner plugin?
  2. If so, how can I properly import and use Flutter in this context?
  3. Are there any specific considerations or limitations when trying to use Flutter with build_runner?

Any insights or solutions would be greatly appreciated. Thank you!


Solution

    1. Using Flutter directly within a build_runner plugin is challenging due to environment limitations. But yes u can, i would suggest u should consider using Dart's reflection
    2. Consider using Dart's reflection to extract widget information .
    3. The main limitations are performance implications, maintainability, and error handling when working with Flutter and build_runner.