mix
mix copied to clipboard
Feature: Widget Builder
Mix currently allows for the creation of functional widgets. However for usability and performance reasons it would be great to have a widget to be built automatically from a Mix.
The API could look something like this.
final _base = Mix(titleCase, textColor(Colors.black),dark(textColor(colors.white)));
@MixTextWidget
final h1 = Mix(apply(_base),fontSize(48));
@ MixTextWidget
final h2 = Mix(apply(_base),fontSize(36));
This would generate the following output. Where WidgetMixes would be a reference to a global reference of the mixes.
class H1 extends StatelessWidget {
const H1(this.text, {Key? key}) : super(key: key);
final String text;
@override
Widget build(BuildContext context) {
return TextMix(WidgetMixes, text: text);
}
}
For the decorator we can have multiple for each particular widget. Box, Flexbox, TextMix, IconMix, or we can pass the widget type as a parameter @MixWidget
@MixWidget(type: MixWidgetType.text, name: 'Heading1');
final h1 = Mix(apply(_base),fontSize(48));
I guess some VS Code extension could be created to generate those widgets
We might explore this further at a later time. However, the Dart team is working on a Macro feature, and we might wait for that to be stable before implementing it.