Skip to content

How to create a widget factory for elements side by side #833

Answered by daohoangson
DFelten asked this question in Q&A
Discussion options

You must be logged in to vote

I think something like this should work https://try.fwfh.dev/?id=d7a0e963f8ba4b1b3c2ddb0fe15540b4

class _WidgetFactory extends WidgetFactory {
  @override
  void parse(BuildMetadata meta) {
    if (meta.element.classes.contains('row')) {
      meta.register(
        BuildOp(
          onWidgets: (meta, widgets) {
            if (widgets.length < 2) {
              return widgets;
            }
            return [Row(children: widgets.toList(growable: false))];
          },
        ),
      );
    }

    return super.parse(meta);
  }
}

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@DFelten
Comment options

Answer selected by DFelten
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@daohoangson
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants