flutter icon indicating copy to clipboard operation
flutter copied to clipboard

[asset_transformers] Provide the current target platform in the asset transformer

Open navaronbracke opened this issue 1 year ago • 4 comments

Use case

Developers wanting to transform assets, based on the current target platform (i.e. flutter build web -> web; flutter build apk -> android), currently cannot infer the target platform during the asset transformation.

Proposal

I propose that the target platform of the flutter build invocation is provided as either an argument, or in Platform.environment. I initially tried checking what is inside Platform.environment and the FLUTTER_BUILD_MODE seems to be there already?

Then I think the easiest thing to do is to also add something like FLUTTER_BUILD_TARGET_PLATFORM to Platform.environment or the args that are passed to the asset transformer, whichever makes more sense / is cleaner from a tool perspective.

Context: I was initially exploring if I could work around the absence of https://github.com/flutter/flutter/issues/141371 using an asset transformer

navaronbracke avatar Nov 22 '24 08:11 navaronbracke

@navaronbracke Can you check if your case is similar to https://github.com/flutter/flutter/issues/143348 ?

darshankawar avatar Nov 22 '24 11:11 darshankawar

The issue https://github.com/flutter/flutter/issues/143348 refers to the asset transformers feature itself. I propose an addition to that feature, by amending the target platform information to the input of the asset transformers.

navaronbracke avatar Nov 22 '24 11:11 navaronbracke

Then I think the easiest thing to do is to also add something like FLUTTER_BUILD_TARGET_PLATFORM to Platform.environment or the args that are passed to the asset transformer, whichever makes more sense / is cleaner from a tool perspective.

This sounds good to me and is something I would be happy to review a PR for 🙂

Otherwise, I don't know when I'll get around to adding this myself.

andrewkolos avatar Nov 22 '24 18:11 andrewkolos

I'll try to see if I can add this in myself someday :)

Relevant code would be adding an extra var here https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/build_system/tools/asset_transformer.dart#L32

and passing it to the environment for the transformer here https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/build_system/tools/asset_transformer.dart#L133-L139

navaronbracke avatar Nov 22 '24 19:11 navaronbracke