How can I create an animation like this in Flutter? I attempted to use AnimatedPositioned,but I encountered difficulty animating more than one circular container (represented by the electrons in the GIF).i want to use AnimatedPositioned to animate a circular container over an SVG image. Specifically, I aim to create an animation of an electrical circuit. but i can’t make electrons animation like GIF electrons animation
2
Answers
After Edit:
Credits to pskink for this solution. It works for any square/rectangle sizes.
See DartPad Demo
Before Edit:
Solution without CustomPaint that works for square only.
See DartPad Demo.
the easiest and the most efficient solution (since no
setState
is used at all and no rebuild is needed for every animation frame) is to useCustomPaint
widget with passing anAnimationController
asrepaint
parameter toCustomPainter
(this is done inFooPainter
constructor:super(repaint: ctrl)
), to make the drawing logic easierAnimationController.unbounded
is used and to make infinite animationanimateWith()
method is called