how to create animations with 3 container - flutter

I want to create a simple animation.
When I click one of this elements, the selected item must grow larger maybe with an animation, and the others they will have to decrease.
I use a GestureDetector()
GestureDetector(
onTap: () => {},
child: Column(children: <Widget>[
Image(
image: AssetImage('images/one.png'),
height: 80,
),
Text(
"One",
textAlign: TextAlign.center,
style: TextStyle(
color: kBlueColor,
fontWeight: FontWeight.bold,
fontSize: 30),
),
]),
),

Check out this tutorial on animation.
You are going to want to create an animation controller. The animation controller will let you play an animation. You will also want to use the transform widget. This will allow the picture that you are using to expand or move when the animation controller is activated. Also check out this tutorial. It's from flutter Europe and it goes in depth on animations.

Related

Flutter: Text animation is not playing

I want to play a text animation only once in my flutter app. For this purpose, I am using this package:
animated_text_kit: ^4.2.2
This is my code:
TableRow( children: [
Column(children:const [Text('Message',style:TextStyle(fontSize: 16))]),
Column(children:[AnimatedTextKit(
animatedTexts: [
TypewriterAnimatedText(
'Hey, sup!',
textStyle: const TextStyle(
fontSize: 16.0,
),
),
],
totalRepeatCount: 1,
)]),
]),
I expect the animation to be played only once. But when I execute the code, the animation doesn't play. It just stays on as a normal text.
How do I fix this issue?
the text is animating but the speed is high therefore you are not able to see it, you can add speed manually,
Here's the code snippet you can try:
TypewriterAnimatedText(
'Hey, sup!',
textStyle: const TextStyle(
fontSize: 16.0,
color: Colors.black,
),
speed: Duration(milliseconds: 500),
)
Hope it helps 😄

Flutter loading text animation

How to achieve this effect with Flutter? Preferably with something like animatedContainer, but not necessarily.
Solution 1:
Look at this package: animated_text_kit
https://pub.dev/packages/animated_text_kit
See the Wavy pattern...
return DefaultTextStyle(
style: const TextStyle(
fontSize: 20.0,
),
child: AnimatedTextKit(
animatedTexts: [
WavyAnimatedText('Hello World'),
WavyAnimatedText('Look at the waves'),
],
isRepeatingAnimation: true,
onTap: () {
print("Tap Event");
},
),
);
Solution 2:
There are several more general packages that provide out of the box and ready to use Loading animations... (but not necessarily the exact same animation from your link)
Links:
https://pub.dev/packages/flutter_easyloading
Flutter loading text animation
Flutter loading text animation

Adding text to a CircleAvatar changes its position in the layout

When adding text to a CircleAvatar, its position in the Layout changes slightly.
Since my CircleAvatars are displayed in a dynamic ListView, where some will be having text and others just an image, they need to be consistent in size and position.
I'm putting just the code example of the CircleAvatar here, since i think its positioning should be completely independent of its contents.
CircleAvatar(
backgroundColor: getColor(),
radius: radius,
child: Text(
initials,
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
fontSize: radius * 0.8,
),
),
);
I tried the following things to get rid of this difference:
fit everything in a ConstrainedBox/SizedBox
set minRadius/maxRadius of the CircleAvatar
centering the text
setting TextStyle.height
placing the Text via Stack
reducing the Size of the Text (changes the amount of the offset, but even a tiny size already messes up the position)
However, nothing of that worked and I couldn't figure out where this difference comes from.
I don't think that it should matter, but it is used in the subtitle of several ListTiles.
Dumbed down example, can easily be tested in DartPad:
ListView(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
children: const [
Card(
child: ListTile(
title: Text("Item1"),
subtitle: CircleAvatar(
backgroundColor: Colors.white,
radius: 12,
),
),
),
Card(
child: ListTile(
title: Text("Item2"),
subtitle: CircleAvatar(
backgroundColor: Colors.white,
radius: 12,
child: Text(
"_",
style: TextStyle(fontSize: 10),
),
),
),
),
]),
The layout looks like this
Overlay of two exact same ListTiles to emphasize the change in position, one with a Text(), and one without
I solved it by simply adding an empty Text to the CircleAvatar that shouldn't contain any.
Not optimal, but at least it's consistent.

Flutter how to remove space or padding from SfRadialGauge

I am using SfRadialGauge plugin its working fine but there I am facing 2 issues.
Its showing lot of space on top, if I give height to container the sizes of SfRadialGauge is reducing also the top space I don't want to reduce size I just want to remove the space
Same space in GaugeAnnotation. I have column inside GaugeAnnotation and need to show little on top.
My code
Widget getSemiCircleProgressStyle() {
return Padding(
padding: const EdgeInsets.all(0.0),
child: Container(
child: SfRadialGauge(axes: <RadialAxis>[
RadialAxis(
showLabels: false,
showTicks: false,
startAngle: 180,
canScaleToFit: true,
endAngle: 0,
radiusFactor: 0.8,
axisLineStyle: AxisLineStyle(
thickness: 0.1,
color: const Color.fromARGB(30, 0, 169, 181),
thicknessUnit: GaugeSizeUnit.factor,
cornerStyle: CornerStyle.startCurve,
),
pointers: <GaugePointer>[
RangePointer(
value: 100,
width: 0.1,
sizeUnit: GaugeSizeUnit.factor,
enableAnimation: true,
animationDuration: 100,
animationType: AnimationType.linear,
cornerStyle: CornerStyle.bothCurve)
],
annotations: <GaugeAnnotation>[
GaugeAnnotation(
positionFactor: 0,
widget: Container(
child: Stack(
alignment: Alignment.center,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(0.0),
child: RatingBarIndicator(
rating: 0.2,
itemBuilder: (context, index) => Icon(
Icons.star,
color: Color(0xffF4D03F),
),
itemCount: 1,
itemSize: 45.0,
direction: Axis.vertical,
),
),
RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(
text: '2',
style: new TextStyle(
fontSize: 40, fontFamily: 'UbuntuRegular')),
new TextSpan(
text: ' /5',
style: TextStyle(
fontSize: 25,
color: Colors.grey[400],
fontFamily: 'UbuntuRegular')),
],
),
),
Text(
'FIFTEEN DAYS SCORE',
style: TextStyle(
color: Colors.grey[400], fontFamily: 'UbuntuMedium'),
)
],
)
],
),
))
]),
])),
);
}
This is how its look like
I have marked the space with red pen. IF any one can help to reduce these spacing I am stuck on this from a day :(
Been having the same problem too.
I found that the solution is to set :
canScaleToFit: false
But, this only works if you use the default circular gauge. For the semi-circular gauge, it will still left some blank spaces at the bottom.
I had the same problem, I guess I'm late but hopefully this can be useful to others.
Premises
Note. At the moment I can't find a way to have FULL control of this widget's white space. I only have found the following workaround to get rid of the white space above and under the gauge.
The library's devs mentioned two things:
"... For better understanding, say if the container has different width and height (say 300x800), we will always take the lowest dimension (here it is the width) to render the radial gauge ..."
"... We are sorry that we cannot provide any workaround to trim ..."
"... as this is the default rendering behaviour of the Radial gauge, we cannot consider your suggestion as a feature request."
The first statement is really useful, as it enables a workaround (see below).
The second statement.. I disagree, that's not something "impossible" to work around with.
The third statement... well that's just depressing.
Workaround
Thanks to the Flutter DevTools, I noted that the Gauge renders a NeedlePointer Widget, which is the one rendering the cursed white space. As the devs mentioned, the gauge takes as much space as it can in the smallest direction.
This means that as long as you restrict height and width, you should be fine. I don't know in which context your Gauge is, but in mine the following code works great.
return LayoutBuilder(
(context, constraints) => Container(
padding: const EdgeInsets.all(0),
height: constraints.maxWidth / 1.5, // WORKAROUND
child: Column(
children: [
Flexible(
child: SfRadialGauge(...),
),
MaybeSomeLabelsWidgets(),
SomeOtherWidgets(),
],
),
),
);
So, the fundamental part here is the fact that height is restricted and that there's a Flexible Widget that lets the Gauge take minimum space. LayoutBuilder in my case/context is useful just because I wanted to render the plot with a "3x2" feeling.
As a last note, keep the canScaleToFit=true, so that your plot is centered (why is it called canScaleToFit? That's another mistery I guess...).
Let me know if this helps.
A simple workaround is to use the ClipRect widget. The following will discard the top 20% of the SfRadialGuage.
ClipRect(
child: Align(
alignment: Alignment.bottomCenter,
heightFactor: 0.8,
child: SfRadialGauge(...)
)
)

how to change the location of my flatbutton in flutter... (from most left to most right)

I have build a simple app to learn flutter. I want to move a flat button to the most right of the screen.
I cant seem to use padding property and I don't know why.
new FlatButton(
onPressed: () => debugPrint("pressed"),
child: new Text("DONATE",
style: new TextStyle(
fontSize: 16,
color: Colors.green[400]
)
)
)
Try this:
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FlatButton(
onPressed: () => debugPrint("pressed"),
child: new Text("DONATE",
style: new TextStyle(
fontSize: 16,
color: Colors.green[400]
)
)
),
],
),
Have you checked out flutter layouts,here
plus padding property is for inside the button to move the button manipulate the margin property.
Hope that helps.