Comments (7)
Hi @mariogorki94, I need some time for investigate it.
Thanks
from theme_extensions_builder.
Thanks @pro100andrey if you need some more info, ready to help!
from theme_extensions_builder.
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:
Thanks
from theme_extensions_builder.
Hi @mariogorki94, any updates?
from theme_extensions_builder.
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.
@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.
Thanks for the fast fix, appreciate it!
from theme_extensions_builder.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from theme_extensions_builder.