mix icon indicating copy to clipboard operation
mix copied to clipboard

Feature: Widget Builder

Open leoafarias opened this issue 4 years ago • 1 comments

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));

leoafarias avatar Sep 09 '21 13:09 leoafarias

I guess some VS Code extension could be created to generate those widgets

bdlukaa avatar May 06 '22 17:05 bdlukaa

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.

leoafarias avatar Jan 16 '24 14:01 leoafarias