Giter Site home page Giter Site logo

animate_to's Introduction

MIT License stars pub version

Buy Me A Coffee

---

Basic usage

1- Create an AnimateToController

final _animateToController = AnimateToController();

2- Wrap the target widget ( the one to animate to) with an AnimateTo widget and pass it the controller

AnimateTo(
    controller: _animateToController,
    child: const Text('Target'),
 ),

3- Wrap the widgets you wish to animate with AnimateFrom widget. The AnimateFrom widget requires a global key which you can create an pass the normal way or have the AnimateToController generate it for you from a given tag.

AnimateFrom(
   key: _animateToController.tag('animate1'), // regularGlobalKey
   child: const Text('Animatable'),
 ),

now trigger the animation by calling

_animateToController.animateTag('animate1');
// or by key 
_animateToController.animate(regularGlobalKey);

complete code

Scaffold(
 body: SizedBox(
   height: 300,
   child: Column(
     children: [
       AnimateTo(
         controller: _animateToController,
         child: const Text('Target'),
       ),
       const SizedBox(height: 100),
       AnimateFrom(
         key: _animateToController.tag('animate1'),
         child: const Text('Animatable'),
       ),
       const SizedBox(height: 24),
       ElevatedButton(
         onPressed: () {
           _animateToController.animateTag('animate1');
         },
         child: const Text('Animate'),
       ),
     ],
   ),
 ),
)

Result

Animating The target widget (the child of AnimateTo)

AnimateTo provides a builder property to animate it's child on new arrivals (On Single animation completion)

AnimateTo(
   controller: _animateToController,
   child: MyCartIcon(),
   builder: (context, child, animation) {
     return Transform.translate(
       offset: Offset(sin(animation.value * 3 * pi) * 3, 0),
       child: child,
     );
   }
),

Transporting data along with the animation

It's possible to have AnimateFrom widget carry data to the target widget by assigning the data you need to transport to the AnimateFrom.value property and receive it inside AnimateTo.onArrival callback

SizedBox(
   height: 320,
   width: 240,
   child: Column(
     mainAxisAlignment: MainAxisAlignment.spaceBetween,
     children: [
       AnimateTo<Color>(
         controller: _animateToController,
         child: Circle(size: 100, color: targetColor),
         onArrival: (color) { // called on animation complete
           setState(() {
             targetColor = Color.lerp(targetColor, color, .5)!;
           });
         },
       ),
       Row(
         mainAxisAlignment: MainAxisAlignment.spaceBetween,
         children: [
           for (int i = 0; i < 3; i++)
             AnimateFrom<Color>(
              /// whatever is passed here is received inside of `AnimateTo.onArrival`
               value: [Colors.red, Colors.green, Colors.orange][i],
               key: _animateToController.tag(i),
               child: InkWell(
                 borderRadius: BorderRadius.circular(24),
                 onTap: () => _animateToController.animateTag(i),
                 child: Circle(
                   size: 50,
                   color: [Colors.red, Colors.green, Colors.orange][i].withOpacity(.85),
                 ),
               ),
             ),
         ],
       ),
     ],
   ),
 )

Support animate_to

You can support animate_to by liking it on Pub and staring it on Github, sharing ideas on how we can enhance a certain functionality or by reporting any problems you encounter and of course buying a couple coffees will help speed up the development process.

animate_to's People

Contributors

milad-akarie avatar

Stargazers

Moshe Dicker avatar Kostia Sokolovskyi avatar  avatar Vitaliy Vostrikov avatar  avatar  avatar Xu Jiaji avatar Jonas avatar Shujaat Ali Khan avatar Bent Hillerkus avatar Trần Truyền avatar  avatar Omar Almgerbie avatar Burak avatar  avatar Dhari avatar Yuxinxin avatar Faheem Ahmad avatar Paul Fauchon avatar Hoàng Tiến Quốc avatar Lars vom Bruch avatar Ilyas LEFEBVRE avatar Dilshan avatar Dung Nguyen Minh avatar  avatar Adrian Pierra Fuentes avatar Alejandro Giubel Hernández Arbelo avatar Thura Aung avatar Musfick Jamil avatar Andrejs Agejevs avatar Arman Turalin avatar Matěj Žídek avatar erfan avatar  avatar Батмэнд Ганбаатар avatar Matthew Jaoudi avatar Stanislav Ilin avatar Faisal Faraj avatar

Watchers

 avatar  avatar

animate_to's Issues

How to customize the animation ?

Great project, easy to implement and works very well.

Is there a way to customize the animation ? The widgets i want to animate are quite big so the scaling effect is a bit too jarring for what i want, i'd love to be able to make the widget scale a bit smaller than what it currently is.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.