Don't force `uses-material-design: true` for root pubspec
Environment
- Dart version: 3.6.0
Problem
When you are using uses-material-design: true in any sub package with the new pub workspaces feature it complains that you also have to add this to the root pubspec.
A monorepo can have lots of packages that aren't bound to Flutter, it doesn't seem right that the root pubspec should need to be polluted with Flutter settings just because one of its sub packages uses it?
I'm sure there was a reason for this design decision, but is there no way around it? And I'm also curious what the reason was?
Expected behavior
Flutter settings should be contained to their own pubspecs.
Actual behavior
You get the following error:
ERROR: package:example has `uses-material-design: true` set but the primary pubspec contains `uses-material-design: false`. If the application needs material icons, then `uses-material-design` must be set to true.
This was not a conscious decision - seems to be a bug in how flutter collects assets.
I was not easily able to reproduce when I tried. What sequence of commands are you running to reproduce this?
The message comes from https://github.com/flutter/flutter/blob/2dad95b21c15e41902f2ea0645d613246b364bce/packages/flutter_tools/lib/src/asset.dart#L392
I'm very happy to hear that this wasn't a conscious decision!
I thought it would reproduce whatever you did in the repo, but that was not the case apparently, what you have to do is run flutter test from the root of the repository, but pointing to the package that you want to run it in, so like this:
flutter test packages/a
If you run that in the MRE I've created here you'll get the error message: https://github.com/spydon/mre_workspaces_material The MRE is just a pub workspaces repository with one flutter package in it.
Maybe this isn't an issue at all then, it seems like it is mandatory to run flutter test from within the individual package root, which isn't that weird.
t seems like it is mandatory to run flutter test from within the individual package root, which isn't that weird.
I think so - though probably we could improve the messaging when that goes wrong.
Thanks for the quick replies, I'll close this and fix it on the melos side.
Aaah, now I found the real issue! I updated the MRE.
So, if you have an example with uses-material-design: true and the package itself doesn't have that, which is very common when you want to present an example for a Flutter package, if you then run flutter test in the package itself it will complain about the example.
Reproduction instructions:
git clone https://github.com/spydon/mre_workspaces_material.git
cd mre_workspaces_material/packages/a
flutter test
Result:
package:example has `uses-material-design: true` set but the primary pubspec contains `uses-material-design: false`. If the application needs material icons, then `uses-material-design` must be set to
@sigurdm Should this issue be filed towards Flutter instead?
@sigurdm Should this issue be filed towards Flutter instead?
I guess it is correctly filed here, because if I remove the example from the workspace list and remove the resolution for it I don't get any warnings.
Well - it has to do with how flutter accounts for assets that doesn't work well with workspaces. So the fix has to happen in flutter/flutter.
But it is probably going to be me working on the fix as it is related to workspaces, so it doesn't matter hugely.
Trying your reproduction it seems that https://github.com/flutter/flutter/pull/160443 will fix this issue.
Trying your reproduction it seems that flutter/flutter#160443 will fix this issue.
Great to hear that there is already a fix in the pipeline, thanks!