How to make animation in flutter - 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).

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 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?

Flutter Rotation X Y Imagen

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

How to use 'AnimatedModalBarrier' in flutter?

I didn't find any example for constructor AnimatedModalBarrier.
Don't know how to use this widget like modalbarrier.
https://api.flutter.dev/flutter/widgets/AnimatedModalBarrier-class.html
const AnimatedModalBarrier({
Key key,
Animation<Color> color,
this.dismissible = true,
this.semanticsLabel,
this.barrierSemanticsDismissible,
}) : super(key: key, listenable: color);
Since AnimatedModalBarrier works by disabling interactions with the widgets behind itself, the common implementation is using a Stack. For example you want to disable interactions with FormWidget, the modal barrier must be placed above the FormWidget
Stack(
alignment: AlignmentDirectional.center,
children: <Widget>[
FormWidget,
_animatedModalBarrier
],
)
To create the AnimatedModalBarrier itself,you need to create an Animation<Color>. You can use ColorTween to create the animation
ColorTween _colorTween = ColorTween(
begin: Color.red
end: Color.blue,
);
AnimationController _animationController = AnimationController(
vsync: this,
duration: const Duration(seconds: 1)
);
Animation<Color> _colorTweenAnimation = _colorTween.animate(_animationController);
_animatedModalBarrier = AnimatedModalBarrier(
color: _colorTweenAnimation
);
Source & Full Code: https://www.woolha.com/tutorials/flutter-using-animatedmodalbarrier-examples

Flutter Scrollcontroller maxScrollExtent doesn't go till the end of list

it stops before last element in list. Is there a way to go till the end container of the last element
controller
..animateTo(
controller.position.maxScrollExtent,
curve: Curves.easeIn,
duration: const Duration(milliseconds: 300),
);
});```
Using Without Animation Solved the Problem
Timer(Duration(milliseconds: 500), () {
controller.jumpTo(controller.position.maxScrollExtent);
});
I think this is the best function to scroll to bottom with a good animation
scrollToBottom() {
if (_chatController.hasClients) {
Future.delayed(const Duration(milliseconds: 500)).then((value) {
_chatController.animateTo(
_chatController.position.maxScrollExtent,
duration: const Duration(milliseconds: 200),
curve: Curves.fastOutSlowIn,
);
});
}
}
In my case the problem was that the elements were not equal in size and the size was not known until rendered. So, the ListView scrolled to its initial estimated maxScrollExtent but while scrolling the elements were rendered and the new maxScrollExtent was bigger. I hacked it by giving it a much bigger value initially:
attachmentsScrollController.animateTo(
attachmentsScrollController.position.maxScrollExtent * 2,
duration: Duration(milliseconds: 300),
curve: Curves.easeInOut);
I had same problem with CustomeScrollView widget, and I solved with this.
CustomScrollView(
controller: Get.find<ChatController>(tag: 'chatDetail')
.scrollController
.value,
reverse: true,
keyboardDismissBehavior:
ScrollViewKeyboardDismissBehavior.onDrag,
physics: ClampingScrollPhysics(),
cacheExtent: 99999, // <-- here !!! ADD THIS CODE
slivers: [
ChatList(
isQuestion: isQuestion,
postCreatedAt: postCreatedAt,
title: title,
),
],
),
my scroll function was normal as we talked before.
void chatScrollUp() async {
await scrollController.value.animateTo(
scrollController.value.position.maxScrollExtent,
duration: Duration(
milliseconds:
(scrollController.value.position.maxScrollExtent / 2).round()),
curve: Curves.easeOutCirc);}
What worked with me is this:
void scrollAnimateToEnd(ScrollController controller) {
Future.delayed(const Duration(milliseconds: 400)).then((_) {
try {
controller
.animateTo(
controller.position.maxScrollExtent,
duration: const Duration(seconds: 1),
curve: Curves.fastOutSlowIn,
)
.then((value) {
controller.animateTo(
controller.position.maxScrollExtent,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
);
});
} catch (e) {
print('error on scroll $e');
}
});
}