Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] Material theme extensions #99

Closed
wants to merge 7 commits into from
Closed

[POC] Material theme extensions #99

wants to merge 7 commits into from

Conversation

bdlukaa
Copy link
Contributor

@bdlukaa bdlukaa commented Oct 7, 2022

#93

The class MixProperty<T> was created, which will be in every mix attribute. With it, it's possible to use values that depends on the current BuildContext. This means it's possible to do both bgColor(Colors.white) and bgColor(theme<MyColors, Color>((colors) => colors.white)).

Added theme, a function that fetches ThemeExtensions from the closest Theme widget. Also a basic example was added to the /demo app. To try it, change the app theme mode (light/dark) and see the "Gradient Box" color change as the theme changes.

Another advantage of this approach is that we now can make use of Material's AnimatedTheme. When a property in your ThemeExtension changes, its lerp function is called and is animated accordingly to the theme. (animate() works with it too, in case you want to delay the animation)

For now, only the following utils are affected: bgColor, margin and height

@bdlukaa bdlukaa marked this pull request as draft October 7, 2022 21:13
@bdlukaa bdlukaa mentioned this pull request Nov 1, 2022
@bdlukaa
Copy link
Contributor Author

bdlukaa commented Nov 5, 2022

Even if we don't want to make use of ThemeExtensions in mix directly, I believe adding a way to access the BuildContext is a must.

However, with the implementation above, we lose the dart type-safety (by using dynamic).

@leoafarias I'd love to hear your thoughts on this

@leoafarias
Copy link
Member

Thanks for the work on this @bdlukaa. We have already 2 abstractions for values of context. Dto and Tokens (Which might rename Refs, want to see how these fit together.

Also the example allows to pass properties directly to a Box, but since Box is a primitive, I don't think a very similar properties is likely on the primitives themselves. For example on the headless widgets this might be different.

I believe this extensions should work similar to the tokens, or see if we can abstract the tokens to take advantage of ThemeExtensions instead of a separate values on MixTheme.

@bdlukaa bdlukaa closed this Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants