Flutter Rotation X Y Imagen - flutter

I have a problem, in the animation, the image rotates first on the X axis and then on the Y axis, but the image is upside down before it rotates. How do I make the image not to be visualized this way?
_controller = (widget.controller ??
AnimationController(vsync: this, duration: widget.duration))
..addListener(() => setState(() {}))
..repeat();
_animation1 = Tween(begin: 0.0, end: 180.0).animate(CurvedAnimation(
parent: _controller,
curve: const Interval(0.0, 0.5, curve: Curves.easeIn)));
_animation2 = Tween(begin: 0.0, end: 180.0).animate(CurvedAnimation(
parent: _controller,
curve: const Interval(0.5, 1.0, curve: Curves.easeInOut)));
transform: Matrix4.identity()
..rotateX((0 - _animation1.value) * valorAngulo)
..rotateY((0 - _animation2.value) * valorAngulo),
This is my code

Related

Flutter - how use "non-linear" animation with LinearProgressIndicator?

I using LinearProgressIndicator in my app. I need use "non-linear" animation with LinearProgressIndicator. I need the indicator to move unevenly (a little slower a little faster).
This my current code:
controller = AnimationController(
vsync: this,
upperBound: 1,
animationBehavior: AnimationBehavior.preserve,
duration: Duration(seconds: widget.duration),
);
....
controller.addListener(() {
setState(() {
.....
});
});
....
LinearProgressIndicator(value: controller.value);
this works fine but is "linear"
I tried:
TweenAnimationBuilder<double>(
tween: Tween<double>(begin: 0.0, end: 2),
duration: const Duration(milliseconds: 3500),
builder: (context, value, _) => LinearProgressIndicator(
value: value,
),)
but it doesn't give "non-linear" animation. how do i get "non-linear" animation for LinearProgressIndicator ? is it possible?

How to add some delay between AnimationController.repeat() in Flutter

I need to add some delay between each iteration of animation gets call to repeat. Something like the following image.
I tried to do it by passing value to the period parameter of the repeat method but it was not what I expected.
_controller = AnimationController(vsync: this, duration: widget.period)
..addStatusListener((AnimationStatus status) {
if (status != AnimationStatus.completed) {
return;
}
_count++;
if (widget.loop <= 0) {
//_controller.repeat(period: Duration(microseconds: 5000));
_controller.repeat();
} else if (_count < widget.loop) {
_controller.forward(from: 0.0);
}
});
I've also tried to add Tween with the animation. That didn't help either. Can you help me clarify where I went wrong?
AnimatedBuilder(
animation: Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: _controller,
curve: Interval(0.5, 1.0)
),
),
child: widget.child,
builder: (BuildContext context, Widget child) => _Shiner(
child: child,
direction: widget.direction,
gradient: widget.gradient,
percent: _controller.value,
enabled: widget.enabled,
),
);
Thanks to #pskink Now it's working as I expected. All you have to do is repeat the controller yourself instead of trying to add delay to controller.repeat()
_controller.addStatusListener((status) {
if(status == AnimationStatus.completed){
Future.delayed(Duration(milliseconds: 5000),(){
if(!mounted){
_controller.forward(from: 0.0);
}
});
}
}

Have multiple intervals in a staggered animation

Hi I was wondering if it was possible to have a tween that can have multiple intervals in a staggered in serval e.g.
opacity goes from 1.0 to 0.0 (% time: 0.45 to 0.5)
then
opacity goes from 0.0 to 1.0 (% time: 0.5 to 0.55)
using a similar tween
opacity1 = Tween<double>(
begin: 1.0,
end: 0.0,
).animate(
CurvedAnimation(
parent: controller,
curve: Interval(
0.45, 0.5,
curve: Curves.ease,
),
),
).NextTween<double>( ///Pseudo code
begin: 0.0,
end: 1.0,
).animate(
CurvedAnimation(
parent: controller,
curve: Interval(
0.5, 0.55,
curve: Curves.ease,
),
),
)
Ok in the end I use a TweenSquence the flutter docs uses the example below which is very helpful link to the docs is Flutter docs.
This example defines an animation that uses an easing curve to interpolate between 5.0 and 10.0 during the first 40% of the animation, remains at 10.0 for the next 20%, and then returns to 5.0 for the final 40%.
final Animation<double> animation = TweenSequence(
<TweenSequenceItem<double>>[
TweenSequenceItem<double>(
tween: Tween<double>(begin: 5.0, end: 10.0)
.chain(CurveTween(curve: Curves.ease)),
weight: 40.0,
),
TweenSequenceItem<double>(
tween: ConstantTween<double>(10.0),
weight: 20.0,
),
TweenSequenceItem<double>(
tween: Tween<double>(begin: 10.0, end: 5.0)
.chain(CurveTween(curve: Curves.ease)),
weight: 40.0,
),
],
).animate(myAnimationController);

How to make animation in flutter

I am trying to slide the logo to right and again come from left
enter image description here
I tried this but it bounces back the logo
void initState() {
super.initState();
_controller = AnimationController(
// duration: const Duration(seconds: 90),
vsync: this,
)..repeat(reverse: false);
_offsetAnimation = Tween<Offset>(
begin: Offset.zero,
end: const Offset(7.1, 7.0),
).animate(CurvedAnimation(
parent: _controller,
curve: Curves.easeOutQuint,
));
}
You can try below code to slide the logo to right and again come from left,
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
)..repeat(reverse: true);
_offsetAnimation = Tween<Offset>(
begin: Offset(-1.0,0.0), // You can change starting position as per your require.
end: const Offset(1.0, 0.0), // You can change ending position as per your require.
).animate(CurvedAnimation(
parent: _controller,
curve: Curves.linear, // You can change animation curve per your require.
));
}
(Refer the Curves class to choose other curves).

How to spin widget form one to another angle over Y-axis in flutter?

I want to spin widget from 270 degreee(intially) to 360 degreee. I tried AnimationController with AnimatedBuilder with Transform, but not able to understand how to build and what lowerbound and uppperbound parameter do.
Here is sample
Inside initState
_controller = AnimationController(
value: 50,
animationBehavior: AnimationBehavior.normal,
duration: const Duration(milliseconds: 800),
vsync: this)
..addListener(() {
print(rotate.value.toString());
setState(() {});
});
rotate = Tween<double>(begin: 0, end: 90).animate(_controller);
Animated Builder is
AnimatedBuilder(
animation: rotate,
builder: (context, child) {
return Transform(
origin: Offset(100,100),
child: getChild(context, percent),
transform: Matrix4.identity()..rotateY(rotate.value/100),
);
},
)
It always rotate 360 degree n number of times. I am not able to understand how it working?