Skip to content

[FR]: Allow generated asset classes to implement custom interfaces (for Modular Architectures & Design Systems) #759

@Mairramer

Description

@Mairramer

Is there an existing issue for this?

  • I have searched the existing issues

Describe the problem

In modular Flutter architectures (Monorepos, micro-frontends, Design Systems), it is common for each package to generate its own assets.gen.dart using flutter_gen.

This creates a type interoperability issue between packages. For example, a Design System package may expose APIs that depend on generated asset types:

sealed class NavItem {
  String get title;
  SvgGenImage get icon;
}

If the consumer app passes its own generated asset (AppAssets.icons.home), Dart reports a type mismatch because each package generates a different SvgGenImage class.

Current workarounds are not ideal:

  • Using dynamic or Object (losing type safety)
  • Excessive import aliasing
  • Creating wrapper classes for every asset

This becomes especially problematic in scalable modular architectures where assets need to move safely across package boundaries.

Describe the solution

Allow generated asset classes to optionally inject custom implements clauses and imports through pubspec.yaml.

Example configuration:

flutter_gen:
  assets:
    outputs:
      asset_class_implements: 'AppIconData'
      asset_class_import: 'package:design_system/utils/app_icon_data.dart'

Generated output:

import 'package:design_system/utils/app_icon_data.dart';

class SvgGenImage implements AppIconData {
  // ...
}

This allows packages to depend on shared abstractions instead of concrete generated classes:

abstract interface class AppIconData {}

sealed class NavItem {
  String get title;
  AppIconData get icon;
}

As a result, assets generated from different packages can interoperate safely while preserving compile-time type safety.

Additional context

Benefits of this approach:

  • Fully opt-in with zero runtime overhead
  • Improves interoperability between Design Systems and consumer apps
  • Preserves strong typing across Monorepos and modular architectures
  • Avoids falling back to dynamic or raw String asset paths
  • Helps future AST-based tooling and asset tree-shaking strategies
  • Aligns with Flutter’s abstraction patterns such as IconData

Example architecture:

Image

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions