Skip to content

Conversation

mosuem
Copy link

@mosuem mosuem commented Sep 1, 2025

Requires flutter config --enable-dart-data-assets.

This is an example of how replacing asset transformers with build/link hooks could look like. The basic idea is that package vector_graphics_compiler exposes a helper method, here compileSvg, which is then called in the package's build hook. Options can be set there as well.

For now, asset transformers and build hooks can simply co-exist - in the future, when hooks are stable enough, we will want to deprecate asset transformers and move towards this mechanism.

@mosuem mosuem changed the title Add example Use hooks instead of asset transformers Sep 3, 2025
@mosuem mosuem requested a review from bkonyi September 3, 2025 13:39
@mosuem mosuem changed the title Use hooks instead of asset transformers Use hooks in addition to asset transformers Sep 4, 2025
@mosuem mosuem marked this pull request as ready for review September 4, 2025 08:13
@mosuem mosuem requested a review from jtmcdole as a code owner September 4, 2025 08:13
Copy link
Contributor

@bkonyi bkonyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -0,0 +1,9 @@
# example

A Flutter showcase for how to replce asset transformers with hooks.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/replce/replace/

@@ -0,0 +1,9 @@
# example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe something more descriptive, like Vector Graphics Compiler - Build Hooks Example

To run execute:
```bash
flutter config --enable-dart-data-assets
flutter run -d linux
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there technical reasons for only supporting this on Linux? Ideally we'd at least support the desktop platforms so that the majority of our users can run this.

);
}

for (final MapEntry<String, Pair> entry in pairs.entries) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: consider using patterns here

for (final MapEntry(key: name, value: Pair(:outputPath)) in pairs.entries) {
  output.assets.data.add(
    DataAsset(
      package: input.packageName,
      name: name,
      file: Uri.file(outputPath),
    ),
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants