[Proposal] Better support for ThemeExtensions
- Dominant language
- Dart
- Stars
- 800
- Forks
- 49
- Avg merge
- 3h 39m
- Merged PRs (30d)
- 22
Description
We can take advantage of Material's theme extensions to replace the current mix theming. Currently, we define global variables and attach value to them in a `MixThemeData`, so that we can use globally.
**Proposal**
A callback based function `theme((T))` that can be called inside a `Mix`. The mixer will look into every attribute for a `theme` and perform the operation based on the current context.
Something like:
```dart
final mix = Mix(
bgColor(theme((myColors) => myColors.brandColor)),
textColor(theme((myColors) => myColors.danger))),
);
// This is from the official example. Link attached below
@immutable
class MyColors extends ThemeExtension {
const MyColors({
required this.brandColor,
required this.danger,
});
final Color? brandColor;
final Color? danger;
...
}
```
**Other things I have considered**
Making `theme` more readable and usable with something like
```dart
final mix = Mix(
bgColor(theme().brandColor),
textColor(theme().danger),
);
```
But I can't seem to find a way where `theme` would have access to the current context
**Additional context**
https://api.flutter.dev/flutter/material/ThemeData/extensions.html
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.