How to animate height of the container relative to its children content? - flutter

I want to animate the height property of the container (AnimatedContainer in code below), but I don't want to set hard numbers like this (height: _visible2 ? 160 : 40.9) because height of this container is otherwise relative to its children content (mainly Text)
AnimatedContainer(
curve: Curves.ease,
height: _visible2 ? 160 : 40.9,
duration: Duration(milliseconds: 350),
child: AnimatedOpacity(
duration: Duration(milliseconds: 400),
opacity: _visible2 ? 1.0 : 0,
child: GestureDetector(
onTap: () {
_visible2
? setState(() {
_visible2 = !_visible2;
})
: null;
},
child: myWidget
),
),
)
Is there a way to animate from zero to relative height (for example height of this container can change in landscape mode due to more room for text to lay itself on the screen) ?

Related

Flutter: animate layout changes

Is it possible to animate page items as they appear? (not with fade effect) like on android, with
android:animateLayoutChanges
Example 1
Example 2.
You can try delayed_display pub package.
But if you want to do something custom, for example:
AnimatedContainer(
duration: Duration(milliseconds: 500),
height: 50,
width: isVisible ? 100 : 50,
color: isVisible ? Colors.yellow : Colors.blue,
);

Different in and out curve for animated opacity widget flutter?

I have code below , a AnimatedOpacity widget with animation curve Curves.elasticIn.
That curve used in both opacity 1 to 0 and 0 to 1.How i can use two different curve for opacity 1 to 0 and 0 to 1. ?
AnimatedOpacity(
opacity: _trueOrFalse? 1.0 : 0.0,
curve: Curves.elasticIn,
duration: const Duration(milliseconds: 2000),
child: Center(
child: SvgPicture.asset("assets/....svg"),
),
You can use it as you have done with opacity.
AnimatedOpacity(
opacity: _trueOrFalse? 1.0 : 0.0,
*//if opacity is 1.0 then use elasticIn Curve else use elasticOut for 0.0 opacity*
curve: _trueOrFalse? Curves.elasticIn: Curves.elasticOut,
duration: const Duration(milliseconds: 2000),
child: Center(
child: SvgPicture.asset("assets/....svg"),
),

Unable to remove overflow error while animation.(flutter)

I write the code to AnimatedContainer and while it s expanding it give me gradual overflow but at full extent it s no more a overflow error. I tried the code on several screens and I don t have any problems. I want.
child: GestureDetector(
onTap: () {
setState(() {
arr[index] = !arr[index];
});
},
child: Center(
child: AnimatedContainer(
width: arr[index] ? 300.0 : 300.0,
height: arr[index] ? 80.0 : 85.0+60.0*clase[index].clase,
alignment:
arr[index] ? Alignment.center : AlignmentDirectional
.center,
duration: Duration(seconds: 1),
curve: Curves.fastOutSlowIn,
child: arr[index] ? Inchis(index) :Deschis(index),//these are the classes
),
),
),
Everything is fine but I want to escape of that little error.
Here is a video
https://imgur.com/0HXoIZN

Flutter Icon Scale

i want to rescale my icon and rotate my icon until it's scale become 0,but i can only 'set' icon's size which means size become instantly 0 without animation, tried to wrap icon with animated container, but it doesn't effect to icon, any ideas for rotating and rescaling icon by time ? my code's here below.
Widget build1(BuildContext context) {
Widget widget1;
var animatedContainer = AnimatedContainer(
width: double.infinity,
height: double.infinity,
duration: Duration(seconds: 2),
color: animSize ? Colors.greenAccent[700] : Colors.yellow,
child: IconButton(
icon: Icon(
Icons.group,
size: animSize ? 0:90,
),
onPressed: () {
setState(() {
animSize = true;
});
},
));
widget1 = animatedContainer;
return widget1;
}

How to really use SizeTransition in Flutter?

I want to make the same effect as this: https://api.flutter.dev/flutter/widgets/SizeTransition-class.html but starting from the beginning of an image. I tried everything and this does not work!
I tried to put Align in it, to put a container with the width modified by the value of the animation.. nothing works!
I have an animation before, and then it will call forward() on this one when it finishes (there is a function called complete that calls the forward() function).
initState() {
_sizeController =
AnimationController(duration: Duration(seconds: 1), vsync: this)
..addListener(() {
setState(() {});
});
_sizeAnimation = Tween(begin: 0.0, end: 27.0).animate(CurvedAnimation(
parent: _sizeController, curve: Curves.fastLinearToSlowEaseIn));
}
AnimatedContainer(
width: _width,
height: _height,
duration: Duration(milliseconds: 200),
decoration: BoxDecoration(
color: _color,
border: Border.all(
color: Color(0xFF707070), width: 2, style: BorderStyle.solid),
borderRadius: BorderRadius.circular(14.0),
),
child: SizeTransition(
sizeFactor: _sizeAnimation,
axis: Axis.horizontal,
axisAlignment: -1,
child:
Center(child: Image.asset('assets/images/check.png')),
),
Or it does nothing or it animates by scaling only.. How can i achieve the same effect as the example video on the widget page? I want that effect to happen showing a checkmark image inside a circle container. And before this the animatedcontainer will be a linear container that turns into the circle, and then the checkmark appears.
you need to call _sizeController.forward() to run the animation