GithubHelp home page GithubHelp logo

Comments (7)

pro100andrey avatar pro100andrey commented on June 27, 2024

Hi @mariogorki94, I need some time for investigate it.

Thanks

from theme_extensions_builder.

mariogorki94 avatar mariogorki94 commented on June 27, 2024

Thanks @pro100andrey if you need some more info, ready to help!

from theme_extensions_builder.

pro100andrey avatar pro100andrey commented on June 27, 2024

Hi @mariogorki94, you should add lerp static function in your MMStateProperties class

class MMStateProperties extends MaterialStateProperty<Color?> {
  @override
  Color ?resolve(Set<MaterialState> states) {
    if (states.contains(MaterialState.disabled)) {
      return Colors.green;
    }

    return Colors.black;
  }

  static MMStateProperties? lerp(
    MMStateProperties? a,
    MMStateProperties? b,
    double t,
  ) {
    return _ColorResolver(a, b, t);
  }
}

class _ColorResolver implements MMStateProperties {
  const _ColorResolver(this.a, this.b, this.t);

  final MaterialStateProperty<Color?>? a;
  final MaterialStateProperty<Color?>? b;
  final double t;

  @override
  Color? resolve(Set<MaterialState> states) {
    final resolvedA = a?.resolve(states);
    final resolvedB = b?.resolve(states);

    return Color.lerp(resolvedA, resolvedB, t);
  }
}

@themeExtensions
class ElevatedButtonThemeExtension
    extends ThemeExtension<ElevatedButtonThemeExtension>
    with _$ThemeExtensionMixin {
  const ElevatedButtonThemeExtension({
    required this.backgroundColor,
    required this.foregroundColor,
    required this.test,
    this.borderRadius,
    this.radius = 5,
  });

  final BorderRadius? borderRadius;
  final MMStateProperties test;
  final double radius;
  final Color backgroundColor;
  final Color foregroundColor;
}

it works:

Screenshot 2023-01-11 at 15 31 44

Thanks

from theme_extensions_builder.

pro100andrey avatar pro100andrey commented on June 27, 2024

Hi @mariogorki94, any updates?

from theme_extensions_builder.

mariogorki94 avatar mariogorki94 commented on June 27, 2024

The proposed solution works if we are extending MaterialState, but if we want to use the default MaterialState class without extending it what may be the possible solution ?
For example here are some properties to work with:

 static final _interactiveStates = {
    MaterialState.pressed,
    MaterialState.selected,
    MaterialState.focused,
    MaterialState.dragged,
    MaterialState.hovered,
  };

 static final redStateColor = MaterialStateProperty.resolveWith((state) {
    if (state.contains(MaterialState.disabled)) return Colors.grey;

    if (state.any(_interactiveStates.contains)) return Colors.green;

    if (state.contains(MaterialState.hovered)) return Colors.blue;

    return Colors.red;
  });

from theme_extensions_builder.

pro100andrey avatar pro100andrey commented on June 27, 2024

@mariogorki94, fixed in 2.0.2

if you want linearly interpolates between two values you should implement lerp(T? a, T? b, double t) for your custom class.

from theme_extensions_builder.

mariogorki94 avatar mariogorki94 commented on June 27, 2024

Thanks for the fast fix, appreciate it!

from theme_extensions_builder.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.