flutter_gen
flutter_gen copied to clipboard
gen runner fails with Bad state: No element
The current version of flutter_gen_runner
failes with the following error:
[SEVERE] flutter_gen_runner:flutter_gen_runner on $package$ (cached):
Bad state: No element
[SEVERE] Failed after 16.0s
Running the build runner in verbose mode does not reveal anything else about the error.
I tried deleting all image and font assets, but that did not fix the problem, so it seems it has nothing to do with a broken file or something like that. I attached the pubspec and lockfile of the project for reference.
Thanks, we are getting this also in version 4.3.0. Version 4.1.6 still works.
FlutterGen v4.3.0 Loading ... pubspec.yaml [SEVERE] flutter_gen_runner:flutter_gen_runner on $package$:
Bad state: No element
New infos: I found the position in the code where the exception is throw: It happens in https://github.com/FlutterGen/flutter_gen/blob/main/packages/runner/lib/flutter_gen_runner.dart#L62
Apparently, the buildStep.findAssets
fails to find the pubspec.yaml. I checked with the debugger, and the config.pubspecFile.path
correctly resolves to "pubspec.yaml"
Note: This first broke in 4.2.0, where that file was greatly changed
Maybe it's too late, but if you have a build.yaml
file then adding - "pubspec.yaml"
to source:
will fix this;
example:
targets:
$default:
sources:
include:
- "pubspec.yaml" # add this line
- $package$
- assets/**
- assets/i18n/**
- lib/**
- swaggers/**
builders:
swagger_dart_code_generator:
options:
input_folder: "swaggers/"
output_folder: "lib/swaggers/gen/"
Maybe it's too late, but if you have a
build.yaml
file then adding- "pubspec.yaml"
tosource:
will fix this; example:targets: $default: sources: include: - "pubspec.yaml" # add this line - $package$ - assets/** - assets/i18n/** - lib/** - swaggers/** builders: swagger_dart_code_generator: options: input_folder: "swaggers/" output_folder: "lib/swaggers/gen/"
@Ahmed-gubara I wrote the build.yaml as per your comment and the problem was solved. Thank you!
Yes, this did work for me as well. Another fix would be to simply delete the build.yaml. My suggestion:
Add a "known issue" to the README, that when using a custom build.yaml, one has to add the "pubspec.yaml" line to the sources.
That would be enough for me and then the issue can be closed.