GIfatahTH / animator

A Flutter library that makes animation easer. It allows for separation of animation setup from the User Interface.
BSD 3-Clause "New" or "Revised" License
227 stars 28 forks source link

Prevent rebuild costly widgets #14

Closed joaomarccos closed 5 years ago

joaomarccos commented 5 years ago

Is there some way to provide a animator child like in animation controller to prevent rebuild expensive widgets??

Something like:

...
return Animator(
      tween: Tween<double>(begin: 0, end: 300),
      cycles: 0,
      child: SomeCostlyOrNotWidget() // <-----
      builder: (anim, child) => Center(
            child: Container(
              margin: EdgeInsets.symmetric(vertical: 10),
              height: anim.value,
              width: anim.value,
              child: child, <--- No rebuild the entire widget
            ),
          ),
    );
...
GIfatahTH commented 5 years ago
final child = YourCostyWidget();

return Animator(
      tween: Tween<double>(begin: 0, end: 300),
      cycles: 0,
      child: SomeCostlyOrNotWidget() // <-----
      builder: (anim,) => Center(
            child: Container(
              margin: EdgeInsets.symmetric(vertical: 10),
              height: anim.value,
              width: anim.value,
              child: child, <--- No rebuild the entire widget
            ),
          ),
    );
joaomarccos commented 5 years ago

Yeah, actually I'm doing this way. But I think it should be possible directly inside the Animator Constructor.