animate a widget continuously different size - flutter

i am trying to create a splash screen that contain animation, of 3 widget.
i notice this:
if the 1st widget animate up the 2nd widget will animate down continuously
while the 3rd flip from right to lift.
How do i move 2 widget with little animation. i using stack with positioned widget in the design.
here is the design code:
Scaffold(
body: Container(
height: double.infinity,
width: double.infinity,
child: Stack(
children: [
SizedBox.expand(
child: Image.asset(
"assets/images/splash.png",
fit: BoxFit.fill,
),
),
Positioned(
right: -150,
child: Transform.rotate(
angle: -math.pi / 4.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 10,
width: 300,
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.5),
borderRadius: BorderRadius.circular(20),
),
),
SizedBox(
height: 15,
),
Container(
height: 25,
width: 400,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
),
SizedBox(
height: 15,
),
Container(
height: 15,
width: 210,
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.9),
borderRadius: BorderRadius.circular(20),
),
)
],
),
),
),
Positioned(
left: 0,
right: 0,
bottom: 10,
top: -120,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Un',
style: TextStyle(
color: Colors.white,
fontSize: 45.sp,
fontWeight: FontWeight.w500),
),
SizedBox(
width: 5,
),
Animator(
tween: Tween(begin: 0.0, end: 6.35),
cycles: 1,
duration: Duration(seconds: 8),
builder: (context, anim, child) => Transform.rotate(
angle: 0,
child: child,
),
child: SvgPicture.asset(
"assets/white_lgo.svg",
width: 50.w,
height: 35.h,
),
),
SizedBox(
width: 5,
),
Text(
'leap',
style: TextStyle(
color: Colors.white,
fontSize: 45.sp,
fontWeight: FontWeight.w500),
),
],
),
),
),
Positioned(
left: -140,
bottom: 320,
child: Transform.rotate(
angle: -math.pi / 4.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 10,
width: 140,
decoration: BoxDecoration(
color: Color(0xff103E3F),
borderRadius: BorderRadius.circular(20),
),
),
SizedBox(
height: 15,
),
Container(
height: 25,
width: 70,
decoration: BoxDecoration(
color: Color(0xff103E3F),
borderRadius: BorderRadius.circular(20),
),
),
SizedBox(
height: 15,
),
Container(
height: 13,
width: 300,
decoration: BoxDecoration(
color: Color(0xff103E3F),
borderRadius: BorderRadius.circular(20),
),
)
],
),
),
),
],
),
),
);
the animation i am trying to achieve
expected
thanks

You should create an animationController like this:
late final AnimationController animationController = AnimationController(
duration: const Duration(milliseconds: 1000),
vsync: this,
);
and then add an animation. This code will generate numbers and you can use these numbers writing _doubleAnimation.value wherever you wanna change. For Example:
late final Animation<double> _doubleAnimation = Tween<double>(
begin: 0.0,
end: 6.34,
).animate(CurvedAnimation(
parent: animationController,
curve: Curves.fastOutSlowIn,
));
and run this function for infinity animation in initState:
animationController.repeat(reverse: true);
If you don't wanna reverse animation, you can change reverse to false.
Lastly, do not forget to use TickerProviderStateMixin. Also, you can take some help from here

Related

Flutter: Gesture detector being used in specific area on sized box

I have something like a tinder card that Id like to be able to detect if a user taps on the left/right area of the card. Its defined by a sized box, but how can i tell a gesture detector to only use a specific part of the given area?
relevant code, you should be able to ignore everything in the stack but i included it in case there was something i was missing:
return Padding(
padding: const EdgeInsets.only(top: 10, left: 20, right: 20),
child: SizedBox(
height: MediaQuery.of(context).size.height / 1.4,
width: MediaQuery.of(context).size.width,
child: GestureDetector(
child: Stack(
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
state.stingrays[index]!.imageUrls[0])),
borderRadius: BorderRadius.circular(5.0),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 4,
blurRadius: 4,
offset: Offset(3, 3),
)
]),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
gradient: LinearGradient(
colors: [
Color.fromARGB(200, 0, 0, 0),
Color.fromARGB(0, 0, 0, 0),
],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
),
),
Positioned(
bottom: 30,
left: 20,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${state.stingrays[index]!.name}, ${state.stingrays[index]!.age}',
style: Theme.of(context)
.textTheme
.headline2!
.copyWith(
color: Colors.white,
),
),
Text(
'${state.stingrays[index]!.jobTitle}',
style: Theme.of(context)
.textTheme
.headline3!
.copyWith(
color: Colors.white,
fontWeight: FontWeight.normal,
),
),
Row(
children: [
Container(
width: 35,
height: 35,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
child: Icon(Icons.info_outline,
size: 25,
color: Theme.of(context).primaryColor),
)
],
)
],
),
),
],
),
),
),
);
Thanks!
I am assuming that the card is placed in the center. Then you can get the coordinates with the following
Add this
onTapDown: (details) {
var position = details.globalPosition;
//Here it's checking if the click position is less than half of screen or more
if (position.dx < MediaQuery.of(context).size.width / 2){
print(" tapped left side");
} else {
print{"tapped right size");
}
},
While Kaushik had a good suggestion, for my case I ended up doing the following:
GestureDetector(
child: LayoutBuilder(builder: (ctx, constraints) {
return Align(
alignment: Alignment.centerRight,
child: Opacity(
opacity: 0.0,
child: Container(
color: Colors.black,
height: constraints.maxHeight,
width: constraints.maxWidth * 0.3,
),
),
);
}), onTap: () {
Provider.of<StingrayBloc>(context, listen: false).add(
IncrementImageUrlIndex(
imageUrlIndex: state.imageUrlIndexes[index],
stingrayIndex: index));
print(state.imageUrlIndexes[index]);
}),

flutter background image carousel

I'm new to flutter and working on developing my flutter coding skills. I want to display 3 background images in a carousel while other texts and button remain same on the screen. in the below code, image carousel is working properly but my Get Started button and other texts not displaying at all. what should I do for correct this issue. appreciate your help on this.
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class Test extends StatelessWidget {
#override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.leanBack);
return Scaffold(
body: ListView(
children: [
CarouselSlider(
items: [
//1st Image of Slider
Container(
color: Colors.black,
child: Stack(
children: [
Positioned.fill(
child: Opacity(
opacity: 0.8,
child: Image.asset('assets/images/person1.png',
fit: BoxFit.cover),
),
),
Container(
color: Color.fromRGBO(5, 65, 196, 0.19),
),
],
),
),
//2nd Image of Slider
Container(
color: Colors.black,
child: Stack(
children: [
Positioned.fill(
child: Opacity(
opacity: 0.8,
child: Image.asset('assets/images/person2.png',
fit: BoxFit.cover),
),
),
Container(
color: Color.fromRGBO(5, 65, 196, 0.19),
),
],
),
),
//3rd Image of Slider
Container(
color: Colors.black,
child: Stack(
children: [
Positioned.fill(
child: Opacity(
opacity: 0.8,
child: Image.asset('assets/images/person3.png',
fit: BoxFit.cover),
),
),
Container(
color: Color.fromRGBO(5, 65, 196, 0.19),
),
],
),
),
],
//Slider Container properties
options: CarouselOptions(
height: 810.0,
enlargeCenterPage: true,
autoPlay: true,
aspectRatio: 16 / 16,
autoPlayCurve: Curves.fastOutSlowIn,
enableInfiniteScroll: true,
autoPlayAnimationDuration: Duration(milliseconds: 800),
viewportFraction: 1,
),
),
Padding(
padding: const EdgeInsets.only(left: 40, bottom: 230),
child: Align(
alignment: Alignment.bottomLeft,
child: Text('Meet \nYour Doctor\nHere',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 35,
color: Color(0xffFAFAFA),
fontWeight: FontWeight.w500,
))),
),
Padding(
padding: const EdgeInsets.only(left: 30, top: 26),
child: Align(
alignment: Alignment.topLeft,
child: Text('DOCTOR',
style: TextStyle(
fontFamily: 'Dubai',
fontSize: 30,
color: Colors.white,
fontWeight: FontWeight.w500,
))),
),
Padding(
padding: const EdgeInsets.only(bottom: 60),
child: Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
width: 320,
height: 65,
child: ElevatedButton(
onPressed: () {},
child: Text(
'Get Started',
style: TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.normal),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(
Color(0xff05ABA3)),
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(50.0),
),
))),
)),
),
Padding(
padding: const EdgeInsets.only(bottom: 20),
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
color: Colors.white,
),
height: 5,
width: 120,
))),
],
),
);
}
}
you can set image in background using BoxDecoration in container-
Container(
height: 120.0,
width: 120.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'imagename'),
fit: BoxFit.fill,
),
shape: BoxShape.circle,
),
)
On your Scaffold's body: you are using ListView. You can still find those widgets by scrolling down.
For your case, you like to have text and button widgets over the UI.
You need to replace ListView with Stack on body.
return Scaffold(
body: Stack( // this
children: [
CarouselSlider
More about Stack and ListView.

I had an error in flutter as "BOTTOM OVERFLOWING BY 1.1 PIXELS" while creating buttons

This is my code. Help me with this:
return SafeArea(
child: Container(
width: size.width,
height: size.height,
color: background,
child: FittedBox(
fit: BoxFit.contain,
alignment: Alignment.center,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(
width: size.width,
height: size.height * 0.1,
child: Padding(
padding: EdgeInsets.zero,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
],
),
),
),
Container(
width: size.width,
height: size.height * 0.25,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(
width: size.width * 0.25,
height: size.height * 0.25,
decoration: new BoxDecoration(
color: buttonBackground,
borderRadius: new BorderRadius.all(
Radius.circular(40.0),
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(
Icons.keyboard_arrow_left,
color: iconButton,
size: 38,
),
Text(
"L&R",
style: TextStyle(
fontWeight: FontWeight.bold,
color: text,
fontSize: 24,
),
),
Icon(
Icons.keyboard_arrow_right,
color: iconButton,
size: 38,
),
],
),
),
Container(
padding: EdgeInsets.zero,
width: size.width * 0.1,
height: size.width * 0.1,
decoration: new BoxDecoration(
gradient: new LinearGradient(
begin: Alignment.topLeft,
end: Alignment.topRight,
colors: [
Colors.blue,
Colors.pink,
],
),
shape: BoxShape.circle,
),
child: Container(
padding: EdgeInsets.zero,
width: size.width * 0.4,
height: size.width * 0.4,
decoration: new BoxDecoration(
color: background,
shape: BoxShape.circle,
),
),
),
Container(
width: size.width * 0.25,
height: size.height * 0.25,
decoration: new BoxDecoration(
color: buttonBackground,
borderRadius: new BorderRadius.all(
Radius.circular(40.0),
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(
Icons.keyboard_arrow_up,
color: iconButton,
size: 38,
),
Text(
"U & D",
style: TextStyle(
fontWeight: FontWeight.bold,
color: text,
fontSize: 24,
),
),
Icon(
Icons.keyboard_arrow_down,
color: iconButton,
size: 38,
),
],
),
),
],
),
),
Container(
width: size.width,
height: size.height*0.23,
),
],
),
),
),
),
);
Try below code hope its helpful to you.
Add your Column Widget inside SingleChildScrollView
SingleChildScrollView(
child:Column(
children:[
//Add your widgets here
],
),
),
I'm trying to reproduce the error, but I need your constants to do so. Can you add the constants.dart file to your question? Or at least the file where you specify size.width and size.height, for example?
That way I can run your code on my computer and see what I can do to help you.
For now, I'm thinking you should probably use Flex widget (https://api.flutter.dev/flutter/widgets/Flex-class.html) to fix this problem without making the app scroll, since that's not always what you want (thinking of a login page or something).

how to stack image to show in the background

Please pardon me to post this.
i am working with this design more that 3 days now i can i get the actual design. all my effort design is been rejected.
i am trying to create this design.
the problem i have is the right and left box showing at the back of the image.
thanks in advance.
here is my code
Container(
child: Card(
shape:RoundedRectangleBorder(borderRadius:
BorderRadius.circular(25.0),
),
semanticContainer:true,
clipBehavior:
Clip.antiAliasWithSaveLayer,
child:Image(image:
NetworkImage(snapshot.data.docs[index].data()['picture'], ),
fit: BoxFit.cover,), ),),);
Scaffold(
body: Container(
height: double.infinity,
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Colors.pinkAccent,
Colors.yellowAccent,
],
),
),
child: Stack(
children: [
Positioned(
left: 70,
// right: 40,
top: 40,
child: Transform.rotate(
angle: pi - 3.30,
child: Container(
// transform: ,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.white.withOpacity(0.2),
),
height: 200,
width: 150,
),
),
),
Positioned(
left: 130,
// right: 150,
top: 78,
child: Transform.rotate(
angle: pi + 3.30,
child: Container(
// transform: ,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.white.withOpacity(0.6),
),
height: 190,
width: 150,
),
),
),
Positioned(
left: 0,
right: 0,
top: 50,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 100.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.white,
image: DecorationImage(
image: NetworkImage("https://picsum.photos/200/300"),
fit: BoxFit.fill
),
),
height: 220,
width: 100,
),
),
),
],
),
),
);
Result
If you like change, black shadow play with stops inside gradient. hope you will get the idea of doing it.
stops: [.5, 1.0],
To AlignWidgte change this valuealignment: Alignment(-1, -1),. For rotation change here. Better use slider or from dart:math use pi.
Transform.rotate(angle: -.166,
Code snippet
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
get imageWidth => 300;
get imageHeight => 450;
double sliderVal = 0.0;
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
buttonTheme: ButtonThemeData(
textTheme: ButtonTextTheme.primary,
),
),
home: Scaffold(
body: Column(
children: [
Slider(
value: sliderVal,
onChanged: (v) {
setState(() {
sliderVal = v;
print(sliderVal);
});
}),
Container(
width: imageWidth * 1.4,
height: imageHeight * 1.1,
child: Stack(
children: [
Align(
alignment: Alignment(-1, -1),
child: Transform.rotate(
angle: -.166,
child: backImage(color: Colors.blue),
),
),
Align(
alignment: Alignment(1, 1),
child: Transform.rotate(
angle: .128,
child: backImage(color: Colors.yellow),
),
),
Center(
child: mainImage(),
),
],
),
),
],
),
),
// CustomSS(),
);
}
backImage({required Color color, double? width, double? height}) {
return Container(
width: width ?? imageWidth,
height: height ?? imageHeight,
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(12),
),
);
}
SizedBox mainImage() {
return SizedBox(
width: imageWidth,
height: imageHeight,
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Stack(
fit: StackFit.expand,
children: [
Image.asset(
"assets/me.jpg",
fit: BoxFit.cover,
),
Container(
decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(12),
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: [.5, 1.0],
colors: [
Colors.transparent,
Colors.black87,
],
),
),
),
Positioned(
bottom: 30,
left: 30,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
children: [
Text(
"Yeasin",
style: TextStyle(
fontSize: 22,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
SizedBox(
width: 8,
),
Text(
"XX",
style: TextStyle(
fontSize: 22,
color: Colors.white,
),
)
],
),
SizedBox(
height: 10,
),
Text(
"Description",
style: TextStyle(
fontSize: 14,
color: Colors.white,
),
),
]),
)
],
),
));
}
}

animatedPositioned is not animated on Flutter

I need to animate widget and I used AnimatedPositioned. but not animated. just change position without animate
Full Code
Column(
children: <Widget>[
Container(
height: 50,
width: width,
color: Palette.white,
child: Padding(
padding: const EdgeInsets.only(left:20.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: 200,
height: 40,
decoration: BoxDecoration(
color: Palette.lightSilver,
borderRadius: BorderRadius.all(Radius.circular(20))
),
child: Stack(
children: <Widget>[
AnimatedPositioned(
right:check? 0:null,
left:check?null: 0,
child: InkWell(
onTap: (){
setState(() =>
check = !check
);
},
child: Container(
width: 110,
height: 40,
decoration: BoxDecoration(
color: Palette.darkSilver2,
borderRadius: BorderRadius.all(Radius.circular(20))
),
),
),
duration: const Duration(milliseconds: 50000),
curve: Curves.bounceOut,
)
],
),
),
],
),
)
),
You just need to set a distance not equal to null from the right and left sides all the time so the container doesn't Jump, I modified the code a little (try it):
Column(
children: <Widget>[
Container(
height: 50,
width: 400,
color: Colors.green,
child: Padding(
padding: const EdgeInsets.only(left: 20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: 300,
height: 40,
decoration: BoxDecoration(
color: Colors.grey,
borderRadius:
BorderRadius.all(Radius.circular(20))),
child: Stack(
children: <Widget>[
AnimatedPositioned(
right: check ? 0 : 200,
left: check ? 200 : 0,
onEnd: () {
print('done');
},
child: InkWell(
onTap: () {
setState(() => check = !check);
},
child: Container(
width: 50,
height: 40,
decoration: BoxDecoration(
color: Colors.black54,
borderRadius: BorderRadius.all(
Radius.circular(20))),
),
),
duration: const Duration(milliseconds: 5000),
curve: Curves.bounceOut,
)
],
),
),
],
),
)),
],
),
You can animate using only left or right property of animated container.
Container(
width: 200,
height: 60,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.all(Radius.circular(20))),
child: Stack(
children: <Widget>[
AnimatedPositioned(
left: check
? 90
: 0, // here 90 is (200(above container)-110(container which is animating))
child: InkWell(
onTap: () {
setState(() {
check = !check;
});
},
child: Container(
width: 110,
height: 40,
decoration: BoxDecoration(
color: Colors.teal,
borderRadius:
BorderRadius.all(Radius.circular(20))),
),
),
duration: const Duration(seconds: 1),
curve: Curves.bounceOut,
),
],
),
),