I am using flutter_gen
to generate assets i.e. pngs and svgs. I have 3 folders in my assets folder defined like this in pubspec.yaml
.
flutter:
uses-material-design: true
generate: true
assets:
- assets/svgs/
- assets/pngs/
- assets/flags/
But the flags svgs are also being generated which I don’t need.
What I actually want:
assets/svgs/... -> should be generated
assets/flags/... -> should not be generated
I tried to define it with exclude
parameter.
flutter_gen:
output: lib/gen/ # Optional (default: lib/gen/)
line_length: 80 # Optional (default: 80)
integrations:
flutter_svg: true
exclude:
- assets/flags/
Is there any way to solve this?
2
Answers
assets/flags/
folder from being processed byflutter_gen
, you’ll need to ensure that your configuration for theflutter_gen
package is correctly set up. Theexclude
parameter should work for this purpose, but it seems like it might not be functioning as expected in your case.Here’s a refined configuration you can try to make sure the exclusion is correctly applied:
Update your
pubspec.yaml
to include theflutter_gen
configuration properly:Notice the use of
/**
to ensure that the exclusion applies to all files within theassets/flags/
directory.Regenerate your assets with
flutter_gen
:Run the following command to regenerate the assets after updating the configuration:
Check the generated files:
After running the above command, verify that the files under
assets/flags/
are not included in the generated assets.If the above steps do not resolve the issue, it’s possible that there’s a bug or limitation in the version of
flutter_gen
you are using. In such cases, consider the following additional steps:Update
flutter_gen
to the latest version:Ensure you are using the latest version of
flutter_gen
by updating yourpubspec.yaml
:Then run:
Manually verify the exclusion pattern:
Ensure that the exclusion pattern
assets/flags/**
matches the directory structure and files you intend to exclude. Sometimes, tweaking the pattern (e.g., tryingassets/flags/*
or other variations) might help.By carefully setting up the
exclude
parameter and regenerating the assets, you should be able to exclude theassets/flags/
directory from being processed byflutter_gen
.I had the same problem.
I forgot to add
assets:
before theexclude:
line.Also, I had to add
/*
after each folder name. Seems like it takes file names only, not whole folders.pubspec.yaml
. Use**
for any folder and*
for any file.fluttergen -c [path-to-pubspec.yaml]
An example of it is on
flutter_gen
‘s repo right here.