Iteo / theme_tailor

Code generator for Flutter's theme extension classes.
https://pub.dev/packages/theme_tailor
MIT License
79 stars 13 forks source link

[Feature]: Why do you delete @Tailor? #106

Closed ChaserVasya closed 2 months ago

ChaserVasya commented 2 months ago

Problem

@Tailor was good decision for my project. I delegate to it many boilerplate. Now I need to write this boilerplate by hand with @TailorMixin.

Desired Solution

Generate theme constructing from static field definitions, like it was with @Tailor

Alternatives Considered

No response

On which platorm do you expect this solution?

All

With @Tailor

This code snippet was generated:

class AppColors extends ThemeExtension<AppColors> with DiagnosticableTreeMixin {
  const AppColors({
    required this.attention,
    required this.buttonBackgroundNotActive,
    required this.buttonBorderSelectorStates,
    required this.buttonOnSurfaceSelectorStates,
    required this.buttonSurfaceSelectorStates,
    required this.buttonText,
    required this.cardBackground,
    required this.cardContentBackground,
    required this.positive,
    required this.primary,
    required this.separator,
    required this.telegramBlue,
    required this.textHint,
    required this.textPrimary,
    required this.textSecondary,
    required this.textSection,
    required this.warning,
    required this.whatsappGreen,
    required this.windowBackground,
  });

  final Color attention;
  final Color buttonBackgroundNotActive;
  final Map<ButtonSelectorState, Color> buttonBorderSelectorStates;
  final Map<ButtonSelectorState, Color> buttonOnSurfaceSelectorStates;
  final Map<ButtonSelectorState, Color> buttonSurfaceSelectorStates;
  final Color buttonText;
  final Color cardBackground;
  final Color cardContentBackground;
  final Color positive;
  final Color primary;
  final Color separator;
  final Color telegramBlue;
  final Color textHint;
  final Color textPrimary;
  final Color textSecondary;
  final Color textSection;
  final Color warning;
  final Color whatsappGreen;
  final Color windowBackground;

  static final AppColors prod = AppColors(
    attention: _$AppColors.attention[0],
    buttonBackgroundNotActive: _$AppColors.buttonBackgroundNotActive[0],
    buttonBorderSelectorStates: _$AppColors.buttonBorderSelectorStates[0],
    buttonOnSurfaceSelectorStates: _$AppColors.buttonOnSurfaceSelectorStates[0],
    buttonSurfaceSelectorStates: _$AppColors.buttonSurfaceSelectorStates[0],
    buttonText: _$AppColors.buttonText[0],
    cardBackground: _$AppColors.cardBackground[0],
    cardContentBackground: _$AppColors.cardContentBackground[0],
    positive: _$AppColors.positive[0],
    primary: _$AppColors.primary[0],
    separator: _$AppColors.separator[0],
    telegramBlue: _$AppColors.telegramBlue[0],
    textHint: _$AppColors.textHint[0],
    textPrimary: _$AppColors.textPrimary[0],
    textSecondary: _$AppColors.textSecondary[0],
    textSection: _$AppColors.textSection[0],
    warning: _$AppColors.warning[0],
    whatsappGreen: _$AppColors.whatsappGreen[0],
    windowBackground: _$AppColors.windowBackground[0],
  );

  static final AppColors odin = AppColors(
    attention: _$AppColors.attention[1],
    buttonBackgroundNotActive: _$AppColors.buttonBackgroundNotActive[1],
    buttonBorderSelectorStates: _$AppColors.buttonBorderSelectorStates[1],
    buttonOnSurfaceSelectorStates: _$AppColors.buttonOnSurfaceSelectorStates[1],
    buttonSurfaceSelectorStates: _$AppColors.buttonSurfaceSelectorStates[1],
    buttonText: _$AppColors.buttonText[1],
    cardBackground: _$AppColors.cardBackground[1],
    cardContentBackground: _$AppColors.cardContentBackground[1],
    positive: _$AppColors.positive[1],
    primary: _$AppColors.primary[1],
    separator: _$AppColors.separator[1],
    telegramBlue: _$AppColors.telegramBlue[1],
    textHint: _$AppColors.textHint[1],
    textPrimary: _$AppColors.textPrimary[1],
    textSecondary: _$AppColors.textSecondary[1],
    textSection: _$AppColors.textSection[1],
    warning: _$AppColors.warning[1],
    whatsappGreen: _$AppColors.whatsappGreen[1],
    windowBackground: _$AppColors.windowBackground[1],
  );

  static final themes = [
    prod,
    odin,
  ];

With @TailorMixin

I write it with myself. It is error-prone work

Rongix commented 2 months ago

Thanks for sharing your thoughts. I understand the frustration with the extra work required by @TailorMixin compared to the old @Tailor approach.

The switch was made because the previous method had some issues, especially with static properties. Working with those was not type-safe and often led to errors when assigning values to the theme. The need for a dummy class for code generation was also problematic—it wasn't really aligned with best practices, like avoiding unnecessary code.

The new approach with @TailorMixin might involve more manual setup, but it's more reliable (you're also able to freely add your own methods and work with other generators without them being handled by the package) and closer to what we envision for the package. There’s a chance things will improve in future Dart releases, especially when macros get fully implemented.