skip to Main Content

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


  1. assets/flags/ folder from being processed by flutter_gen, you’ll need to ensure that your configuration for the flutter_gen package is correctly set up. The exclude 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:

    1. Update your pubspec.yaml to include the flutter_gen configuration properly:

      flutter:
        uses-material-design: true
        generate: true
        assets:
          - assets/svgs/
          - assets/pngs/
          - assets/flags/
      
      flutter_gen:
        output: lib/gen/ # Optional (default: lib/gen/)
        line_length: 80 # Optional (default: 80)
      
        integrations:
          flutter_svg: true
      
        exclude:
          - assets/flags/**
      

      Notice the use of /** to ensure that the exclusion applies to all files within the assets/flags/ directory.

    2. Regenerate your assets with flutter_gen:

      Run the following command to regenerate the assets after updating the configuration:

      flutter pub run build_runner build
      
    3. 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 your pubspec.yaml:

      dev_dependencies:
        flutter_gen: ^x.y.z  # Replace with the latest version
      

      Then run:

      flutter pub get
      
    • 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., trying assets/flags/* or other variations) might help.

    By carefully setting up the exclude parameter and regenerating the assets, you should be able to exclude the assets/flags/ directory from being processed by flutter_gen.

    Login or Signup to reply.
  2. I had the same problem.

    I forgot to add assets: before the exclude: line.
    Also, I had to add /* after each folder name. Seems like it takes file names only, not whole folders.

    1. Update the pubspec.yaml. Use ** for any folder and * for any file.
    flutter_gen:
      assets: # add this
        exclude:
          # if you need to exclude any file inside any folder that is inside the flags folder
          - assets/flags/**/*
                  
          # if you need to exclude any file inside the flags folder only
          - assets/flags/*
    
    1. Run fluttergen -c [path-to-pubspec.yaml]

    An example of it is on flutter_gen‘s repo right here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search