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

DebugFilleProperties not generated #59

Closed jtdLab closed 1 year ago

jtdLab commented 1 year ago

Given: https://github.com/Iteo/theme_tailor/blob/main/packages/theme_tailor/example/lib/diagnosticable.dart

The generated file looks like this:

// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, unused_element

part of 'diagnosticable.dart';

// **************************************************************************
// ThemeTailorGenerator
// **************************************************************************

class MyTheme extends ThemeExtension<MyTheme> {
  const MyTheme({
    required this.background,
    required this.textStyle,
  });

  final Color background;
  final TextStyle textStyle;

  static final MyTheme light = MyTheme(
    background: _$MyTheme.background[0],
    textStyle: _$MyTheme.textStyle[0],
  );

  static final MyTheme dark = MyTheme(
    background: _$MyTheme.background[1],
    textStyle: _$MyTheme.textStyle[1],
  );

  static final themes = [
    light,
    dark,
  ];

  @override
  MyTheme copyWith({
    Color? background,
    TextStyle? textStyle,
  }) {
    return MyTheme(
      background: background ?? this.background,
      textStyle: textStyle ?? this.textStyle,
    );
  }

  @override
  MyTheme lerp(ThemeExtension<MyTheme>? other, double t) {
    if (other is! MyTheme) return this;
    return MyTheme(
      background: Color.lerp(background, other.background, t)!,
      textStyle: TextStyle.lerp(textStyle, other.textStyle, t)!,
    );
  }

  @override
  bool operator ==(Object other) {
    return identical(this, other) ||
        (other.runtimeType == runtimeType &&
            other is MyTheme &&
            const DeepCollectionEquality()
                .equals(background, other.background) &&
            const DeepCollectionEquality().equals(textStyle, other.textStyle));
  }

  @override
  int get hashCode {
    return Object.hash(
        runtimeType,
        const DeepCollectionEquality().hash(background),
        const DeepCollectionEquality().hash(textStyle));
  }
}

extension MyThemeBuildContextProps on BuildContext {
  MyTheme get _myTheme => Theme.of(this).extension<MyTheme>()!;
  Color get background => _myTheme.background;
  TextStyle get textStyle => _myTheme.textStyle;
}
jtdLab commented 1 year ago

Am i missing smth ?

Rongix commented 1 year ago

Hey, thanks for reporting the issue. I will have a look

Rongix commented 1 year ago

The fix is available on the develop branch and will be published to pub.dev later this month, you can use it right by changing version of the package in the pubspec to the following:

  theme_tailor:
    git:
      url: https://github.com/Iteo/theme_tailor.git
      path: packages/theme_tailor
      ref: develop
jtdLab commented 1 year ago

Great 👍 thanks a lot.