Skip to content

AnimatedBuilder should be renamed  #19255

Closed

Description

@rrousselGit

The class AnimatedBuilder should have its name replaced. As it is not related to animation in reality.

For example, the following is possible :

final valueNotifier = ValueNotifier(0);

AnimatedBuilder(
  animation: valueNotifier,
  builder: (context, _) {
    return Text(valueNotifier.value.toString());
  },
)

Same goes for ScrollController, ...

I suggest to rename it to ListenableBuilder as it makes more sense.

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Jul 11, 2018
  2. zoechi commented on Jul 11, 2018

    @zoechi
    Contributor
  3. rrousselGit commented on Jul 11, 2018

    @rrousselGit
    ContributorAuthor

    We can raise the same question about AnimatedWidget. Ultimately it faces the same problem.
    Although AnimatedWidget is more honest about its behavior. As AnimatedWidget has its parameter named listenable. While AnimatedBuilder named it animation instead.


    These names would be fine if the parameter had for type Animation<T> instead of Listenable.

    Maybe an alternative is to keep AnimatedBuilder/Widget but with the type Animation<T>. And change the builder to

    Widget animationBuilder(BuildContext context, Widget chid, T value);
    

    And then offer a ListenableBuilder/Widget as a replacement to the current API.

  4. Hixie commented on Jul 12, 2018

    @Hixie
    Contributor

    AnimatedWidget used to take an Animation, we changed it to a Listenable much later in its life (when it was first invented, Listenable didn't exist).

    Changing this would be a very breaking change, it's probably too late to really make changes here. But it's something we can study when we look at the animation API updates we've discussed.

  5. added this to the milestone on Jul 12, 2018
  6. rrousselGit commented on Jul 13, 2018

    @rrousselGit
    ContributorAuthor

    A bit off topic but where can I find that "animation API update discussion"?

  7. zoechi commented on Jul 25, 2018

    @zoechi
    Contributor

    Is #19637 #19729 related?

  8. xster commented on Jul 27, 2018

    @xster
    Member

    I'm assuming you linked the wrong PR and are probably referring to #19729. I originally wanted to extract some base class out of the AnimatedBuilder but I think there's something inconvenient in the existing API (where the listable wasn't passed back into the builder closure signature). Since a ValueListenableBuilder is as much an encapsulation mechanism as a triggering mechanism, it would be inappropriate for its owner to pass the listenable back into the builder function instead of being self sufficient.

    TL;DR, we're unlikely to rename the AnimatedBuilder and you can consider using the ValueListenableBuilder once the PR is merged.

  9. rrousselGit commented on Jul 28, 2018

    @rrousselGit
    ContributorAuthor

    That's already a pretty good start, nice !

    In the continuation of this PR, would it be valid if I contributed with an ListenableBuilder and ScrollControllerBuilder ?


    Back on the topic, can't we create an AnimationBuilder and mark AnimatedBuilder as @deprecated with other the new builders listed as alternatives ?

    AnimationBuilder would be fine as name considering it would listen Animation. Afterall we don't have a StreamedBuilder but SteamBuilder.

  10. xster commented on Jul 28, 2018

    @xster
    Member

    Ha, we actually made one too
    #18136 (for scrolling), though we didn't check it in because we weren't sure if people would use it.

    Regarding the existing API, like Hixie said, we're unfortunately unlikely to change it.

  11. rrousselGit commented on Jul 28, 2018

    @rrousselGit
    ContributorAuthor

    Regarding the scroll builder, I was thinking of listening ScrollController instead of notifications.

    I used this pattern a lot for things like parallax or when I need to align an overlay next to a scroll item. Which wouldn't be possible with notifications.

    It would also make it more user friendly then notifications I guess

  12. Hixie commented on Jul 28, 2018

    @Hixie
    Contributor

    I would recommend making packages for these.

  13. zoechi commented on Aug 21, 2018

    @zoechi
    Contributor

    Does #19729 solve this?

  14. 9 remaining items

  15. escamoteur commented on Oct 23, 2019

    @escamoteur
    Contributor

    IMHO we should discuss what possibilities we have here. It's really difficult for beginners to understand that an animation just triggers Listenables and therefore the AnimationBuilder can be used with any Listenable

  16. changed the title [-]AnimatedBuilder should be renamed[/-] [+]AnimatedBuilder should be renamed [/+] on Jan 10, 2020
  17. dungnv2602 commented on Mar 5, 2020

    @dungnv2602

    Please Flutter team, by any means I can't swallow this, it keeps annoying me all the time cause it sounds horribly wrong.
    Stream => StreamBuilder
    ValueListenable => ValueListenableBuilder
    Listenable => AnimatedBuilder

  18. ozburo commented on Mar 28, 2020

    @ozburo

    Well, whether or not you guys decide to rename this Class or not, I learned something today 👍

    Now I don't need to populate my initState and setState with tons of ScrollController offsets/etc and simply delegate that to AnimatedBuilder for each of my Widgets that need them.

    IMO the real confusion is around the member name animation which implies you need an instance of AnimationController and not any controller -- perhaps this is what needs to be changed or made more "generic".

    In any case thanks for teaching me something, I feel this a level up in terms of mastering Flutter and should be required reading 💯

  19. added
    P2Important issues not at the top of the work list
    on May 29, 2020
  20. removed this from the milestone on Aug 17, 2020
  21. esDotDev commented on Jan 20, 2021

    @esDotDev

    Curious why we wouldn't slap an @deprecated on the AnimatedBuilder and replace with ListenableBuilder? After a cpl yrs, pull it out?

    While at it, a "plural" version of this would be quite nice as well. Sometimes you have multiple listenables, changing any of them requires a rebuild, nice not to have to nest builders at the same pt in the tree.

  22. icnahom commented on Sep 9, 2021

    @icnahom
    Contributor

    While at it, a "plural" version of this would be quite nice as well. Sometimes you have multiple listenables, changing any of them requires a rebuild, nice not to have to nest builders at the same pt in the tree.

    Try passing them to Listenable.merge(), and use this listenable in an AnimatedBuilder.

    And it would be great if the team accepts your suggestions about slowly moving to ListenableBuilder.

  23. mateusfccp commented on Jan 25, 2022

    @mateusfccp
    Contributor

    Yeah, I think this is totally doable now. We could simply introduce this:

    @Deprecated('Use ListenableBuilder and bla bla bla ')
    typedef AnimatedBuilder = ListenableBuilder;

    And then we remove it completely in a later stable version.

    I don't think it's much of a hassle...

  24. albertodev01 commented on Jan 26, 2022

    @albertodev01
    Contributor

    There is a new PR (#97256) to try to solve this issue

  25. esDotDev commented on Nov 10, 2022

    @esDotDev

    Just to kick the tires on this a bit, #95967 (comment)

    Actually, I'm a bit unsure if we want to create an alias for an existing API (AnimatedBuilder), just for the sake of it being more discoverable. This might confuse API users as well - why are there two classes doing the same thing?

    It would not primarily be to make it more discoverable (though that is a side-benefit), it would be so we can write proper semantic code that reads correctly and does not mis-lead the reader. Using something called AnimatedBuilder when no Animation is in play, is just plain confusing.

    From a comment above

    It's really difficult for beginners to understand that an animation just triggers Listenables and therefore the AnimationBuilder can be used with any Listenable

    The duplicated functionality would not really be confusing if AnimatedBuilder is deprecated, and eventually removed after a few yrs.

    We have just started using something like this to make semantics more clear:

    class ListenableBuilder extends AnimatedBuilder {
      const ListenableBuilder({
        Key? key,
        required Listenable listenable,
        required TransitionBuilder builder,
        Widget? child,
      }) : super(key: key, animation: listenable, builder: builder, child: child);
    }
  26. github-actions commented on Mar 5, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  27. locked as resolved and limited conversation to collaborators on Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: animationAnimation APIsc: API breakBackwards-incompatible API changesc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions