Skip to content

Wildcarding assets in pubspec.yaml (or allow an entire directory to be included) #4890

Closed

Description

@apwilson

I'd like to be able to add an entire folder of assets without having to enumerate each one in my flutter.yaml.

Activity

  1. modified the milestone: on Sep 12, 2016
  2. changed the title [-]FR: Wildcarding assets in flutter.yaml (or allow an entire directory to be included)[/-] [+]FR: Wildcarding assets in pubspec.yaml (or allow an entire directory to be included)[/+] on Jan 31, 2017
  3. changed the title [-]FR: Wildcarding assets in pubspec.yaml (or allow an entire directory to be included)[/-] [+]Wildcarding assets in pubspec.yaml (or allow an entire directory to be included)[/+] on Jan 31, 2017
  4. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Jan 31, 2017
  5. modified the milestones: , on Jan 31, 2017
  6. eseidelGoogle commented on Mar 10, 2017

    @eseidelGoogle
    Contributor

    Here is the handling of the assets key, probably pretty easy to add this (and make other improvements to this logic):
    https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/asset.dart#L343

  7. eseidelGoogle commented on May 11, 2017

    @eseidelGoogle
    Contributor

    We're looking to remove .flx files entirely in #9900 which will likely change how we specify assets.

  8. dragonfax commented on Oct 18, 2017

    @dragonfax

    Still no solution for this? I have a lot of images in my app, and I'm adding more all the time.

  9. 38 remaining items

  10. zoechi commented on Jun 26, 2018

    @zoechi
    Contributor

    @bunopus seems to be only in master yet. See #16413
    You also need flutter/flutter-intellij#2384 which will probably included in the next Flutter IntelliJ plugin update.

    Not sure about VSCode @DanTup do you know about that?

  11. bunopus commented on Jun 26, 2018

    @bunopus

    @zoechi thanks! Found related bug dart-lang/sdk#33550
    Ignore it for now, but it's really confusing, because it's in the docs on https://flutter.io/assets-and-images/

  12. DanTup commented on Jun 26, 2018

    @DanTup
    Contributor

    Looks like the fix is in the analysis server, so VS Code doesn't require any changes. You'll get the fix when you get a new Flutter that has a new SDK in it (same as for IntelliJ) 😄

  13. fmatosqg commented on Jul 10, 2018

    @fmatosqg
    Contributor

    @DanTup hey I was going through dart-lang/sdk#33550 but that's a workaround. Are you aware of a definitive fix for this? if not, I'd like to open new ticket/reopen the above one, and in the mean time add the workaround above in the documentation as a PR.

  14. DanTup commented on Jul 10, 2018

    @DanTup
    Contributor

    @fmatosqg The issue is fixed (dart-lang/sdk@d895b49 - it's linked in dart-lang/sdk#33550 (comment)) - the workaround is a temporary fix you can use until you get a version of Flutter that includes the fix.

  15. fmatosqg commented on Jul 10, 2018

    @fmatosqg
    Contributor

    @DanTup awesome :)
    Is there a easy way to know when that change trickles down to flutter master, without checking dart commit hash with flutter --version and cloning dart to track it? I understand the idea but not sure if there's an easy way to know, and occasionally people come to me asking about this issue.

    I understand that is not usually needed though.

    Bot idea: register your email for when a given dart/flutter commit reaches master / dev / beta

  16. DanTup commented on Jul 10, 2018

    @DanTup
    Contributor

    @fmatosqg If you click on the changeset above, you can see the tags shown on GitHub:

    screen shot 2018-07-10 at 4 30 44 pm

    The oldest one there is the one you care about (dev64 in this case).

    When you run flutter --version, it includes the Dart SDK version:

    dantup-macbookpro:Dart-Code dantup$ flutter --version
    Flutter 0.5.7-pre.83 • channel master • https://github.com/DanTup/flutter.git
    Framework • revision b931640c1d (10 hours ago) • 2018-07-10 06:51:12 +0100
    Engine • revision 6fe748490d
    Tools • Dart 2.0.0-dev.63.0.flutter-4c9689c1d2 <------
    

    You can see this one says dev.63. So it's not in master yet, but you should be able to tell when it is fairly easily.

    Bot idea: register your email for when a given dart/flutter commit reaches master / dev / beta

    Yeah, a generic GitHub bot you can mention on an issue that pings you when it hits a release would be awesome; but hard to implement (hard to generically tie issues to releases). A more specific one (eg. just Flutter) would be easier, but less awesome!

  17. jayrmotta commented on Jul 24, 2018

    @jayrmotta

    Guys, the only issue with this new implementation ending the folder name with a slash is that it only gets the parent folder but not it's children, it would be good to be able to do this recursively since I'm trying to package a web application there during the migration to flutter.

    Something like assets/**/ or assets/**/*.

  18. fmatosqg commented on Jul 24, 2018

    @fmatosqg
    Contributor

    Hey,

    You can read the comments on the pr, there I explain why the approach you mention is a big risk for breaking backwards compatibility in the future.

    Also, web! = flutter. There are assumptions made in the specs that are unique to flutter.

  19. YK-Unit commented on Feb 26, 2020

    @YK-Unit

    Hi, all:

    I'm a member of Fly-Mix Team from NetEase company. My team did develop a flutter development tool: Flr(Flutter-R) to support the feature that you want.

    Flr is a flutter resource manager tool, which can help flutter developer to auto specify assets in pubspec.yaml and generate r.g.dart file which likes R.java in Android after he changes the flutter project assets. With r.g.dart, flutter developer can apply the asset in code by referencing it's asset ID function, such as:

    import 'package:flutter_r_demo/r.g.dart';
    
    // test_sameName.png
    var normalImageWidget = Image(
      width: 200,
      height: 120,
      image: R.image.test_sameName(),
    );
    
    // test_sameName.gif
    var gifImageWidget = Image(
      image: R.mage.test_sameName_gif(),
    );
    
    // test.svg
    var svgImageWidget = Image(
      width: 100,
      height: 100,
      image: R.svg.test(width: 100, height: 100),
    );
    
    // test.json
    var jsonString = await R.text.test_json();
    
    // test.yaml
    var yamlString = await R.text.test_yaml();

    PS: yes, it is just like the AAPT(Android Asset Packaging Tool) in Android.

    Up to now, Flr has supported Android Studio Plugin, CLI, and VSCode Extension:

    1. Flr Android Studio Plugin Version

    2. Flr CLI Version

    3. Flr VSCode Extension Version

  20. flutter-clutter commented on Mar 23, 2021

    @flutter-clutter

    Hey guys. Can we expect this to be implemented in the foreseeable future? There are numerous cases I can think of, in which an asset directory along with its sub directories and the files (or short: recursive definition of asset files) is totally necessary. It's very cumbersome to let an external tool do that.

  21. github-actions commented on Aug 4, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  22. locked as resolved and limited conversation to collaborators on Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: new featureNothing broken; request for a new capabilitytoolAffects the "flutter" command-line tool. See also t: labels.waiting for PR to land (fixed)A fix is in flight

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions