r_flutter icon indicating copy to clipboard operation
r_flutter copied to clipboard

Remove restriction for assets to be inside lib folder

Open maks opened this issue 5 years ago • 5 comments

Now that build package has addressed this issue and assets top-level folder is white-listed, I think it could be possible to remove the restriction requiring assets to be within the lib folder? Which would be great as that would match with recommended flutter project structure.

I'd be happy to try to contribute a PR for this if that would be helpful?

maks avatar Dec 19 '19 04:12 maks

Thank you. that sounds very promising. Pull Request are always welcome

timfreiheit avatar Dec 19 '19 08:12 timfreiheit

@timfreiheit actually it all seems to work fine with those build package updates with no code changes needed in r_flutter!

In your example app, I moved assets out of lib and into the top-level as per std Flutter project layout and updated paths in pubspec.yaml to match.

I then tested by adding the latest builder version:

dev_dependencies:
  flutter_test:
    sdk: flutter
  r_flutter:
    path: ../
  build_runner:   

AND removing the builders: section due to the current breakage in Flutter SDK as I mentioned previously and instead just using the "old way" of: flutter packages pub run build_runner build and it generated .dart_tool/build/generated/example/lib/assets.dart correctly as expected.

Is it worht me submitting a PR updating the Readme and example app code?

maks avatar Mar 03 '20 07:03 maks

That is very interesting. It seams like the build_runner now works correctly with r_flutter. Last time I tested this it caused some problems but I can not remember what kind. When there are no problems with using build_runner instead of builder it would be good to use this as the recommended way since many people will most likely use additional code generators

timfreiheit avatar Mar 03 '20 11:03 timfreiheit

@timfreiheit do you mean #14 ? Unfortunately I think @szotp answers muddied the waters abit on that issue as from what I understand Flutters new integrated code gen functionality, aka "builders section" in pubspec.yaml is actually just built on top of using build_runner package, as can be seen in the PR that implemented it.

The key thing to understand is that Flutters integrated code gen is currently broken due to a bug that made it all that way from dev to stable without being corrected.

But apart from the above Flutter bug, I was actually incorrect in my original comment opening this issue, as per the explaintation I got from the build package team, because in r_flutter you get the assets file list by reading the files/dirs listed in pubspec.yaml you dont actually need the fixes I mentioned and per my test yesterday it works if your assets directory is in the usual Flutter layout of being top-level.

So to sum up, I think what is needed is just to update the Readme and example for people to see that they can use r_flutter with a top-level assets dir.

maks avatar Mar 04 '20 01:03 maks

The reason the constraint about the assets in the lib folder exists was that the code generator was that files outside of the lib where not tracked for changed and would not trigger the code generation again in case files changed. The problem does not really exists when using build_runner directly as far as I can see because you would trigger the the code generation manually using flutter packages pub run build_runner build

timfreiheit avatar Mar 05 '20 14:03 timfreiheit