Flutter container transform - flutter

I wanna transform and pin top right my container when scroll. I show in image. How can I do this ?

first you will need to use either a state management method or the setState() method. You can do this with an if of two cases (true / false). finally have int values ​​with a height and width that control this condition. If you want to add it in an animation, the codes below will help you.
AnimatedContainer(
width: width,
height: height.value,
decoration: BoxDecoration(
color: kAffirmativeColor,
borderRadius: BorderRadius.circular(12),
),
duration: const Duration(milliseconds: 200),
curve: Curves.fastOutSlowIn,)

Related

how to change image opacity within Image() widget - flutter

So am trying to change image opacity using the opacity property i found in Image() widget, this is a short code to be clear :
Padding(
padding: EdgeInsets.all(10.0),
child: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Image(
image: NetworkImage(challengeImage),
fit: BoxFit.cover,
height: 150,
width: 350,
opacity: //not sure how to use
),
),
),
),
the image is a network image i retrieved from Firestore and am not sure what is the value i should put if its not double in order to apply opacity on the image. i thought to create a stack and insert asset image as a layer above my image and use the filter property but i would really like to know how the opacity can work with my code above, Thank you.
You can use AlwaysStoppedAnimation or create an Animation<double>
Image(
image: NetworkImage(""),
opacity: AlwaysStoppedAnimation(.1),
),
Another solution : wrap the widget with Opacity Widget
it accepts a double value in range [0,1] where 1 is fully displaying and 0 is not

How to animate color transitions in flutter?

I'm creating a custom checkbox-like widget that uses Card. I'm able to get the colors changing if the values are the same onTap. However, I want it to transition the color instead of it suddenly changing.
Here's my code:
return Card(
color: selected ? AppColors.primary : AppColors.primaryLight,
I'm relatively new to animations in Flutter, but coming from a strong Frontend/CSS understanding, the way I could achieve something like this is to add transition on a CSS property -- is there something similar to this in Flutter? If not, could someone point me in the right direction?
What I would do is instead of using the Card widget, I would use an AnimatedContainer and have the same condition as you for the color parameter. You will get a smooth transition when the selected value changes. However, you may need to also add boxShadow to have the same elevation effect as Card
AnimatedContainer(
duration: const Duration(milliseconds: 700),
curve: Curves.easeInOut,
decoration:BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 5,
spreadRadius: 5,
offset: Offset(0, 2),
),
],
color: selected ? AppColors.primary : AppColors.primaryLight,
),
)
One way to do this would be an AnimatedContainer
return Card(
child: AnimatedContainer(
duration: const Duration(milliseconds: 1000),
height: 200,
width: 200,
color: selected ? Colors.red : Colors.blue,
child: FooWidget(),
),
)

flutter animation acceleration or speed change

how can we change the acceleration of the animation in duration or make some stops in it's duration?
for example scale a widget to 2x in 3 second than stop for a second than scale it for another 2x in 3 seconds.
AnimationController_anim1 = AnimationController(
vsync: this,
duration: Duration(milliseconds: 3000),
);
ScaleTransition(
scale: Tween(begin: 1.0, end: 2).animate(_anim1),
child: ClipRect(
clipBehavior: Clip.hardEdge,
child: OverflowBox(
maxHeight: 70,
maxWidth: 70,
child: Center(
child: Container(
decoration: BoxDecoration(
color: Colors.white38,
shape: BoxShape.circle,
),
),
),
),
),
)
You can use Curve class which provides a way to map the unit interval of animation to the desired unit interval that your want
for example, curves should implement a transform function whic are mapper that receives a time value in a range of 0,1 which indicates animations current time progress and you can return a value to indicate what should be the new progress of the animation for example you can say if time is greater than 0 then return time2 which speeds up your animation as 2x also note that you should are allowed to return value in the range of 0 to 1 so in this example, your should bound the time2 to be at most 1
Here is link to Curve class documentation :
https://api.flutter.dev/flutter/animation/Curve-class.html
also, there are a few ready to use curves in the Curves class that you can already use or look to the implementation of those to inspire :
https://api.flutter.dev/flutter/animation/Curves-class.html
as I searched around, I found the solution in two different ways, one is what Amir Hossein Mirzaei mentioned, which use Curve class, it is very powerful and flexible but it is a bit complicated and hard solution (beside being so powerful), but the second way is more handy which handled by TweenSequence as bellow :
1 - make an animation controller 2- make TweenSequence and add TweenSequenceItem for each step of animation 3- set it to widget
AnimationController _anim1 = AnimationController(
vsync: this,
duration: Duration(milliseconds: 8500),
//reverseDuration: Duration(milliseconds: 1000),
)..repeat(reverse: true);
Animation<double> _animation1 = TweenSequence(
<TweenSequenceItem<double>>[
TweenSequenceItem<double>(
tween: Tween<double>(begin: 1.0, end: 1.5),
weight: 23.5,
),
TweenSequenceItem<double>(
tween: ConstantTween<double>(1.5),
weight: 6.0,
),
TweenSequenceItem<double>(
tween: Tween<double>(begin: 1.5, end: 2.0),
weight: 23.5,
),
TweenSequenceItem<double>(
tween: ConstantTween<double>(2.0),
weight: 47.0,
),
],
).animate(_anim1);
ScaleTransition(
scale: _animation1,
child: ClipRect(
clipBehavior: Clip.hardEdge,
child: OverflowBox(
maxHeight: 70,
maxWidth: 70,
child: Center(
child: Container(
decoration: BoxDecoration(
color: Colors.white38,
shape: BoxShape.circle,
),
),
),
),
),
)

Flutter Different sized Circles in a shape that don't overlap

I am new to flutter and have this question. How circles with different radius can be placed on a canvas without overlapping on one another in a circular shape? Please note that the circles are of different radius. I am using CustomPaint() and Paint() to draw these circles. Much appreciate your help
I took Sarvesh Dalvi's comment and used Container instead of Custom Paint. Later moved to Ink and Inkwell to get the ripple effect when the bubble is clicked. I used flutter_scatter to display circles in a circle/arc form and SlideTransition to give the floating effect to the bubbles. Below is the code that I came up with.
// Code for Circle
child: Ink(
width: widget.bubbleData.radius,
height: widget.bubbleData.radius,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(widget.bubbleData.image),
fit: BoxFit.scaleDown,
),
shape: BoxShape.circle,
border: Border.all(color: Colors.transparent),
gradient: LinearGradient(colors: widget.bubbleData.colors)),
child: InkWell(
customBorder: CircleBorder(),
splashColor: widget.bubbleData.splashColor,
onTap: () {
print("Circle Tapped");
},
// Code for circles in an arc form
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Scatter(
delegate:
LogarithmicSpiralScatterDelegate(
ratio: 1, a: 1, b: 1, step: 0.01, rotation: 0.3),
children: bubbleList),
));
}

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