Skip to content

Flutter's Listenable use case #23

@goderbauer

Description

@goderbauer

Using Listenables in stateful widgets often has a lot of boilerplate, see example in https://gist.github.com/goderbauer/b82efcb154c3fe1814a0d0b60d277def:

  • listener is added in initState
  • listener is moved to new object in didUpdateWidget
  • listener is removed in dispose
  • (often) a method calling an empty setState is needed

We discussed this use case in our initial brainstorm and I am now curious if we could reduce this boilerplate using this macro prototype.

When I experimented with this, I often got stuck wanting to put a macro on the controller field in the StatefulWidget, which would then generate the required logic in the initState, didUpdateWidget, and dispose methods of the associated State class. However, having the macro on a field affect methods in another class isn't possible. :)

Opening this issue to discuss other ideas for how this boilerplate can be reduced with macros.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions