fade growing animation flutter - flutter

I am trying to achieve the following result in one of my app in flutter.
But I cannot figure out how to animate the "SKYGOAL" text that comes fading and sliding.
I've animated the rest of the components using AnimatedContainer or AnimatedOpacity, but I've been stuck on this one. I am new to animations so I don't know much.
Any help would be useful.
Thank you!
My current related snippet is :
class SplashScreen1 extends StatefulWidget {
const SplashScreen1({Key? key}) : super(key: key);
#override
State<SplashScreen1> createState() => _SplashScreen1State();
}
class _SplashScreen1State extends State<SplashScreen1> with SingleTickerProviderStateMixin {
double _skygoalLogoOpacity = 0;
double _syjOpacity = 0;
double _skygoalTextWidth = 0;
#override
void initState() {
// TODO: implement initState
super.initState();
Future.delayed(const Duration(seconds: 0)).then((value) => setState(() {
_skygoalLogoOpacity = 1;
_syjOpacity = 1;
_skygoalTextWidth = 2000;
}));
Future.delayed(const Duration(milliseconds: 4800)).then((value) => Navigator.pushReplacement(context, AnimatedPageRoute(SplashScreen2())));
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Color(0xFF0E3C6E),
width: MediaQuery.of(context).size.width,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(height: 250,),
Stack(
children: [
Container(
decoration: BoxDecoration(
shape: BoxShape.circle, color: Colors.white
),
height: 185,
width: 185,
),
AnimatedOpacity(
duration: const Duration(milliseconds: 1000),
opacity: _skygoalLogoOpacity,
child: Container(
padding: EdgeInsets.only(top: 20),
child: Image.asset("assets/images/skygoal-logo.png"),
// height: 135,
width: 164,
),
),
],
),
Stack(
children: [
AnimatedOpacity(
duration: const Duration(milliseconds: 2000),
opacity: _syjOpacity,
child: Container(
margin: EdgeInsets.only(left: 40, top: 37),
height: 29,
width: 153,
child: Image.asset("assets/images/start-your-journey.png"),
),
),
Container(
margin: EdgeInsets.only(top: 5,left: 20),
child: Text(
"SKYGOAL",
style: GoogleFonts.poppins(
fontSize: 30,
fontWeight: FontWeight.w800,
color: Colors.white
),
textAlign: TextAlign.center,
),
),
],
),
Spacer(),
Text(
"By Skygoal",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 13
),
),
Container(
margin: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10)
),
height: 5,
width: 134,
)
],
),
),
);
}
}

You can try animated_text_kit fade transition.
Example from doc
return SizedBox(
width: 250.0,
child: DefaultTextStyle(
style: const TextStyle(
fontSize: 32.0,
fontWeight: FontWeight.bold,
),
child: AnimatedTextKit(
animatedTexts: [
FadeAnimatedText( "SKYGOAL"),
],
onTap: () {
print("Tap Event");
},
),
),
);

I dont know whether it is the correct solution or not, But you can try something like this . I created a stack and its first child is the text and the other child is a container with boxShadow . Have a look at this.
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key,}) : super(key: key);
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
MediaQueryData mediaQueryData = MediaQuery.of(context);
return Scaffold(
appBar: AppBar(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: mediaQueryData.size.width,
width: mediaQueryData.size.width,
child: ColoredBox(
color: Colors.yellowAccent,
child: Stack(
alignment: Alignment.centerRight,
children: [
Container(
width: mediaQueryData.size.width,
height: 80,
alignment: Alignment.center,
child: Text(
'Hello World',
style: TextStyle(
fontSize: mediaQueryData.textScaleFactor * 50,
),
),
),
TweenAnimationBuilder(
tween: Tween<double>(
end: 0,
begin: 1,
),
duration: const Duration(
seconds: 5,
),
builder: (context, double tween, _ ){
return Container(
//alignment: Alignment.centerRight,
height: 50, //mediaQueryData.size.width,
width: mediaQueryData.size.width * tween,
decoration: const BoxDecoration(
color: Colors.yellowAccent,
boxShadow: [
BoxShadow(
blurRadius: 80,
spreadRadius: 30,
color: Colors.yellowAccent,
),
]
),
);
},
)
],
),
),
)
],
),
),
);
}
}

Related

Sliding fading animation in flutter

I am trying to achieve the following result in one of my app in flutter.
But I cannot figure out how to animate the "SKYGOAL" text that comes fading and sliding.
I've animated the rest of the components using AnimatedContainer or AnimatedOpacity, but I've been stuck on this one. I am new to animations so I don't know much.
Any help would be useful.
Thank you!
My current related snippet is :
class SplashScreen1 extends StatefulWidget {
const SplashScreen1({Key? key}) : super(key: key);
#override
State<SplashScreen1> createState() => _SplashScreen1State();
}
class _SplashScreen1State extends State<SplashScreen1> with SingleTickerProviderStateMixin {
double _skygoalLogoOpacity = 0;
double _syjOpacity = 0;
double _skygoalTextWidth = 0;
#override
void initState() {
// TODO: implement initState
super.initState();
Future.delayed(const Duration(seconds: 0)).then((value) => setState(() {
_skygoalLogoOpacity = 1;
_syjOpacity = 1;
_skygoalTextWidth = 2000;
}));
Future.delayed(const Duration(milliseconds: 4800)).then((value) => Navigator.pushReplacement(context, AnimatedPageRoute(SplashScreen2())));
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Color(0xFF0E3C6E),
width: MediaQuery.of(context).size.width,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(height: 250,),
Stack(
children: [
Container(
decoration: BoxDecoration(
shape: BoxShape.circle, color: Colors.white
),
height: 185,
width: 185,
),
AnimatedOpacity(
duration: const Duration(milliseconds: 1000),
opacity: _skygoalLogoOpacity,
child: Container(
padding: EdgeInsets.only(top: 20),
child: Image.asset("assets/images/skygoal-logo.png"),
// height: 135,
width: 164,
),
),
],
),
Stack(
children: [
AnimatedOpacity(
duration: const Duration(milliseconds: 2000),
opacity: _syjOpacity,
child: Container(
margin: EdgeInsets.only(left: 40, top: 37),
height: 29,
width: 153,
child: Image.asset("assets/images/start-your-journey.png"),
),
),
Container(
margin: EdgeInsets.only(top: 5,left: 20),
child: Text(
"SKYGOAL",
style: GoogleFonts.poppins(
fontSize: 30,
fontWeight: FontWeight.w800,
color: Colors.white
),
textAlign: TextAlign.center,
),
),
],
),
Spacer(),
Text(
"By Skygoal",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 13
),
),
Container(
margin: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10)
),
height: 5,
width: 134,
)
],
),
),
);
}
}
You can use animated_text_kit's fade animation
Example and result from doc
return SizedBox(
width: 250.0,
child: DefaultTextStyle(
style: const TextStyle(
fontSize: 32.0,
fontWeight: FontWeight.bold,
),
child: AnimatedTextKit(
animatedTexts: [
FadeAnimatedText('SKYGOAL'),
],
),
),
);

NoSuchMethodError: Class 'List<Data> has no instance getter

I have gridviewbuilder that takes data from itemGriddata which has onTap function that directs it to a new page that takes data from that model as well but when I click on it the error in the title appears, any help or some kind of enlightement would be appreciated
this is gridview page
import 'package:flutter/material.dart';
import 'package:wild_wild_rift/builds/SinglePage.dart';
import 'package:wild_wild_rift/data/model.dart';
import 'package:google_fonts/google_fonts.dart';
class GridViewPage extends StatefulWidget {
#override
_GridViewPage createState() => _GridViewPage();
}
class _GridViewPage extends State<GridViewPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.grey,
automaticallyImplyLeading: true,
title: const Text(
'Champions',
style: TextStyle(
fontFamily: 'Lexend Doca',
color: Colors.white,
fontSize: 32,
fontWeight: FontWeight.bold,
),
),
elevation: 2,
),
body: Column(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(15, 15, 15, 15),
child: GridView.builder(
itemCount: itemGriddata.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
childAspectRatio: 1,
),
itemBuilder: (context, index) {
return GridSingleItem(
itemGriddata: itemGriddata[index],
onTap: () async {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SinglePage(itemGriddata[index])));
},
);
},
),
),
),
],
));
}
}
class GridSingleItem extends StatelessWidget {
final itemGriddata;
final Function onTap;
const GridSingleItem({Key key, #required this.itemGriddata, this.onTap})
: super(key: key);
#override
Widget build(BuildContext context) {
return InkWell(
onTap: onTap,
child: ClipRRect(
borderRadius: BorderRadius.circular(5),
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: const Color(0xEEEEEE),
image: DecorationImage(
fit: BoxFit.cover,
image: Image.asset(itemGriddata.image).image,
),
boxShadow: const [
BoxShadow(
blurRadius: 3,
color: Color(0xDA000000),
)
],
borderRadius: BorderRadius.circular(9),
border: Border.all(
color: Colors.black,
),
),
child: Align(
alignment: AlignmentDirectional(-0.45, 0.85),
child: Text(
itemGriddata.name,
style: TextStyle(
fontFamily: 'Lexend Deca',
color: Color(0xFFFFFCFC),
fontWeight: FontWeight.normal,
shadows: [
Shadow(
blurRadius: 8.0,
color: Colors.black,
offset: Offset(1.0, 1.0),
),
],
),
),
),
),
),
);
}
}
this is page that I'd want to take data
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import '../data/model.dart';
class SinglePage extends StatefulWidget {
#override
_SinglePage createState() => _SinglePage();
final Data data;
SinglePage(this.data);
}
class _SinglePage extends State<SinglePage> {
PageController pageViewController;
bool isFirstButton = false;
bool isSecondButton = false;
#override
void initState() {
super.initState();
pageViewController = PageController(initialPage: 0);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: const Color(0xFF090F13),
automaticallyImplyLeading: true,
title: Text(
itemGriddata.name,
style: TextStyle(
fontFamily: 'Lexend Deca',
color: Colors.white,
fontSize: 32,
fontWeight: FontWeight.bold,
),
),
actions: const [],
centerTitle: false,
elevation: 2,
),
backgroundColor: const Color(0xFF262D34),
body: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(0, 0, 0, 25),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Row(
mainAxisSize: MainAxisSize.max,
children: [
Material(
color: Colors.transparent,
elevation: 3,
child: Container(
width: MediaQuery.of(context).size.width,
height: 150,
decoration: BoxDecoration(
color: const Color(0xFF090F13),
image: DecorationImage(
fit: BoxFit.cover,
image: Image.asset(
itemGriddata.backgroundimage,
).image,
),
),
),
),
],
),
Padding(
padding:
const EdgeInsetsDirectional.fromSTEB(20, 12, 20, 0),
child: Row(
mainAxisSize: MainAxisSize.max,
children: const [
Text(
'Choose role',
style: TextStyle(
fontFamily: 'Lexend Deca',
color: Color(0xFF8B97A2),
fontSize: 14,
fontWeight: FontWeight.normal,
),
),
],
),
),
Padding(
padding:
const EdgeInsetsDirectional.fromSTEB(0, 12, 1, 0),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
16, 0, 0, 0),
child: InkWell(
onTap: () async {
isSecondButton = false;
isFirstButton = true;
setState(() {});
await pageViewController.animateToPage(
0,
duration: const Duration(milliseconds: 500),
curve: Curves.ease,
);
},
child: Material(
color: Colors.transparent,
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: const Color(0xFF090F13),
borderRadius: BorderRadius.circular(8),
shape: BoxShape.rectangle,
border: isFirstButton
? Border.all(color: Colors.white)
: null),
child: Stack(
children: [
Align(
alignment: const AlignmentDirectional(
0, -0.05),
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Image.asset(
'assets/images/icon-position-jungle.png',
width: 50,
height: 50,
fit: BoxFit.cover,
),
const Padding(
padding: EdgeInsetsDirectional
.fromSTEB(0, 8, 0, 0),
child: AutoSizeText(
'BUILD 1',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Lexend Deca',
color: Color(0xFF8B97A2),
fontSize: 14,
fontWeight:
FontWeight.normal,
),
),
),
],
),
),
],
),
),
),
),
),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
16, 0, 0, 0),
child: Material(
color: Colors.transparent,
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: const Color(0xFF090F13),
borderRadius: BorderRadius.circular(8),
border: isSecondButton
? Border.all(color: Colors.white)
: null),
child: InkWell(
onTap: () async {
isSecondButton = true;
isFirstButton = false;
setState(() {});
await pageViewController.animateToPage(
1,
duration:
const Duration(milliseconds: 500),
curve: Curves.ease,
);
},
child: Stack(
children: [
Align(
alignment: const AlignmentDirectional(
0, -0.05),
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Image.asset(
'assets/images/icon-position-jungle.png',
width: 50,
height: 50,
fit: BoxFit.cover,
),
const Padding(
padding: EdgeInsetsDirectional
.fromSTEB(0, 8, 0, 0),
child: AutoSizeText(
'BUILD 2',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Lexend Deca',
color: Color(0xFF8B97A2),
fontSize: 14,
fontWeight:
FontWeight.normal,
),
),
),
],
),
),
],
),
),
),
),
),
],
),
),
),
Padding(
padding:
const EdgeInsetsDirectional.fromSTEB(20, 8, 20, 8),
child: Row(
mainAxisSize: MainAxisSize.max,
children: const [
Text(
'Builds',
style: TextStyle(
fontFamily: 'Lexend Deca',
color: Color(0xFF8B97A2),
fontSize: 14,
fontWeight: FontWeight.normal,
),
),
],
),
),
SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
16, 8, 16, 0),
child: Container(
width: MediaQuery.of(context).size.width,
height: 200,
decoration: BoxDecoration(
color: const Color(0x00090F13),
boxShadow: const [
BoxShadow(
blurRadius: 3,
color: Colors.transparent,
offset: Offset(0, 2),
)
],
borderRadius: BorderRadius.circular(8),
),
child: SizedBox(
width: double.infinity,
height: 500,
child: PageView(
controller: pageViewController,
scrollDirection: Axis.horizontal,
children: [
Image.asset(
'assets/images/image_1.png',
width: 100,
height: 100,
fit: BoxFit.cover,
),
Image.asset(
'assets/images/image_2.png',
width: 100,
height: 100,
fit: BoxFit.scaleDown,
),
],
),
),
),
),
],
),
),
],
),
),
),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(20, 0, 20, 8),
child: Row(
mainAxisSize: MainAxisSize.max,
children: const [
Text(
'Text',
style: TextStyle(
fontFamily: 'Poppins',
color: Color(0xFF8B97A2),
),
),
],
),
),
],
),
),
);
}
}
and this is the model with data
final dynamic itemGriddata = [
Data(
name: "Ahri",
image: "assets/images/Ahri.png",
backgroundimage: "assets/images/Ahri_0.jpg"),
Data(
name: "Akali",
image: "assets/images/Akali.png",
backgroundimage: "assets/images/Akali_0.jpg")
];
class Data {
final String name;
final String image;
final String backgroundimage;
Data({this.name, this.image, this.backgroundimage});
}
The issue is that your SinglePage widget has a prop named final Data data; but the _SinglePageState widget is calling itemGriddata for your title and images. You'll need to change your code like so:
class SinglePage extends StatefulWidget {
const SinglePage(Key? key, this.data): super(key: key);
final Data data;
#override
State<StatefulWidget> createState() => _SinglePageState();
}
class _SinglePageState extends State<SinglePage> {
// use widget.data to get name, image, and backgroundImage
// ex... widget.data.name or widget.data.image
#override
Widget build(BuildContext context) {
return Text(widget.data.name);
}
}
You're passing the data correctly to SinglePage, but just change a few lines to ensure you're calling something with actual data! :D

How to use Flutter AnimatedContainer with height matching child

Currently this code works to resize a container to toggle between different content, but it's not animating. I think that I need to provide a height property to make the animation work, and when I do provide a height to toggle between it does match, like this:
height: selected ? 400 : 100,
The container animates smoothly between the two states. However the height is no longer adaptive. So I try to supply a height using:
GlobalKey _key = GlobalKey();
_size = _key.currentContext.size;
height: _size.height,
But it gives me errors and I'm not sure how to fix it.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool selected = false;
// GlobalKey _key = GlobalKey();
// Size _size = _key.currentContext.size;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: ListView(
children: [
GestureDetector(
onTap: () {
setState(() {
selected = !selected;
// _size = _key.currentContext.size;
});
},
child: Padding(
padding: EdgeInsets.all(5),
child: AnimatedContainer(
// height: _size.height,
// key: _key,
duration: Duration(seconds: 1),
curve: Curves.fastOutSlowIn,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 2.5,
spreadRadius: 0.4,
color: Colors.grey,
offset: Offset(0, 0.5),
),
],
),
child: Padding(
padding: EdgeInsets.all(17),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Move fridge up stairs',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 5),
Text(
'Sarah - 2 days ago - 2.3km',
style: TextStyle(color: Colors.black54),
),
if (selected)
Container(
child: Column(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 20, 0, 20),
child: Text(
'Fridge is a single door. Sitting in kitchen. Need one strong person as I will help move it.',
style: TextStyle(
color: Colors.black54,
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.calendar_today,
color: Colors.black54,
size: 20,
),
Text(
' In three days',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.attach_money,
color: Colors.black54,
),
Text(
' 30',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Row(
children: [
Text('Price : '),
Container(
width: 140,
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white,
border: Border.all(color: Colors.white),
),
child: Container(
child: TextField(
decoration: new InputDecoration(
hintText: "Your price",
contentPadding: const EdgeInsets.all(10.0)),
keyboardType: TextInputType.number,
maxLines: null,
),
),
),
],
),
Row(
children: [
Text('Reply : '),
Expanded(
child: TextField(
decoration: new InputDecoration(
hintText: "Enter your reply",
contentPadding: const EdgeInsets.all(10.0)),
keyboardType: TextInputType.multiline,
maxLines: null,
),
),
],
),
SizedBox(height:20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 10,
),
FlatButton(
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.blue, width: 1, style: BorderStyle.solid),
borderRadius: BorderRadius.circular(50),
),
color: Colors.white,
textColor: Colors.black,
onPressed: () {
/*...*/
},
child: Padding(
padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Text(
"Reply",
),
),
),
],
)
],
),
),
],
),
),
),
),
),
],
),
),
],
)
);
}
}
I thing AnimatedContainer is not Appropriate for this situation. I think its better to use AnimatedCrossFade. The AnimatedContainer will automatically animate between the old and new values of properties when they change using the provided curve and duration.
following code is refactored for using AnimatedCrossFade:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool selected = false;
// GlobalKey _key = GlobalKey();
// Size _size = _key.currentContext.size;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: ListView(
children: [
GestureDetector(
onTap: () {
setState(() {
selected = !selected;
// _size = _key.currentContext.size;
});
},
child: Padding(
padding: EdgeInsets.all(5),
child: AnimatedCrossFade(
duration: Duration(seconds: 1),
crossFadeState: selected
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
firstChild: Container(
// height: !selected ? 100 : 400,
// key: _key,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 2.5,
spreadRadius: 0.4,
color: Colors.grey,
offset: Offset(0, 0.5),
),
],
),
child: Padding(
padding: EdgeInsets.all(17),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Move fridge up stairs',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 5),
Text(
'Sarah - 2 days ago - 2.3km',
style: TextStyle(color: Colors.black54),
),
if (selected)
Container(
child: Column(
children: [
Padding(
padding:
EdgeInsets.fromLTRB(0, 20, 0, 20),
child: Text(
'Fridge is a single door. Sitting in kitchen. Need one strong person as I will help move it.',
style: TextStyle(
color: Colors.black54,
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.calendar_today,
color: Colors.black54,
size: 20,
),
Text(
' In three days',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.attach_money,
color: Colors.black54,
),
Text(
' 30',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Row(
children: [
Text('Price : '),
Container(
width: 140,
margin:
EdgeInsets.fromLTRB(0, 0, 0, 0),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(20.0),
color: Colors.white,
border:
Border.all(color: Colors.white),
),
child: Container(
child: TextField(
decoration: new InputDecoration(
hintText: "Your price",
contentPadding:
const EdgeInsets.all(
10.0)),
keyboardType:
TextInputType.number,
maxLines: null,
),
),
),
],
),
Row(
children: [
Text('Reply : '),
Expanded(
child: TextField(
decoration: new InputDecoration(
hintText: "Enter your reply",
contentPadding:
const EdgeInsets.all(10.0)),
keyboardType:
TextInputType.multiline,
maxLines: null,
),
),
],
),
SizedBox(height: 20),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 10,
),
FlatButton(
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.blue,
width: 1,
style: BorderStyle.solid),
borderRadius:
BorderRadius.circular(50),
),
color: Colors.white,
textColor: Colors.black,
onPressed: () {
/*...*/
},
child: Padding(
padding: EdgeInsets.fromLTRB(
0, 10, 0, 10),
child: Text(
"Reply",
),
),
),
],
)
],
),
),
],
),
),
),
secondChild: Container(
// height: !selected ? 100 : 400,
// key: _key,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 2.5,
spreadRadius: 0.4,
color: Colors.grey,
offset: Offset(0, 0.5),
),
],
),
child: Padding(
padding: EdgeInsets.all(17),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Move fridge up stairs',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 5),
Text(
'Sarah - 2 days ago - 2.3km',
style: TextStyle(color: Colors.black54),
),
],
),
),
),
),
),
),
],
),
),
],
));
}
}
You can use custom animation to do this, like this:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
bool selected = false;
GlobalKey _key1 = GlobalKey();
GlobalKey _key2 = GlobalKey();
AnimationController _controller;
Animation _animation;
bool foward = false;
#override
void initState() {
super.initState();
_controller =
AnimationController(vsync: this, duration: Duration(seconds: 1));
}
#override
void dispose() {
_controller.dispose();
super.dispose();
}
#override
void didChangeDependencies() {
super.didChangeDependencies();
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
_animation = Tween<double>(
begin: _key1.currentContext.size.height,
end: _key2.currentContext.size.height +
_key1.currentContext.size.height)
.chain(CurveTween(curve: Curves.fastOutSlowIn))
.animate(_controller);
});
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: ListView(
children: [
Padding(
padding: EdgeInsets.all(5),
child: GestureDetector(
onTap: () {
if (foward) {
_controller.reverse();
} else {
_controller.forward();
}
foward = !foward;
},
child: (_animation == null)
? _buildWidget(_key1, _key2)
: AnimatedBuilder(
// curve: Curves.fastOutSlowIn,
animation: _controller,
builder: (context, child) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 2.5,
spreadRadius: 0.4,
color: Colors.grey,
offset: Offset(0, 0.5),
),
],
),
child: Padding(
padding: EdgeInsets.all(17.0),
child: Container(
height: _animation.value, child: child),
));
},
child: _buildWidget(_key1, _key2)),
),
),
],
)));
}
Widget _buildWidget(Key key1, Key key2) {
return SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Widget1(
key: _key1,
),
Widget2(
key: _key2,
),
],
),
);
}
}
class Widget1 extends StatefulWidget {
Widget1({Key key}) : super(key: key);
#override
_Widget1State createState() => _Widget1State();
}
class _Widget1State extends State<Widget1> {
#override
Widget build(BuildContext context) {
return Column(mainAxisSize: MainAxisSize.min, children: [
Text(
'Move fridge up stairs',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 5),
Text(
'Sarah - 2 days ago - 2.3km',
style: TextStyle(color: Colors.black54),
),
]);
}
}
class Widget2 extends StatefulWidget {
Widget2({Key key}) : super(key: key);
#override
Widget2State createState() => Widget2State();
}
class Widget2State extends State<Widget2> {
#override
Widget build(BuildContext context) {
return Column(mainAxisSize: MainAxisSize.min, children: [
Container(
child: Column(children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 20, 0, 20),
child: Text(
'Fridge is a single door. Sitting in kitchen. Need one strong person as I will help move it.',
style: TextStyle(
color: Colors.black54,
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.calendar_today,
color: Colors.black54,
size: 20,
),
Text(
' In three days',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.attach_money,
color: Colors.black54,
),
Text(
' 30',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Row(
children: [
Text('Price : '),
Container(
width: 140,
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white,
border: Border.all(color: Colors.white),
),
child: Container(
child: TextField(
decoration: new InputDecoration(
hintText: "Your price",
contentPadding: const EdgeInsets.all(10.0)),
keyboardType: TextInputType.number,
maxLines: null,
),
),
),
],
),
Row(
children: [
Text('Reply : '),
Expanded(
child: TextField(
decoration: new InputDecoration(
hintText: "Enter your reply",
contentPadding: const EdgeInsets.all(10.0)),
keyboardType: TextInputType.multiline,
maxLines: null,
),
),
],
),
SizedBox(height: 20),
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
SizedBox(
width: 10,
),
FlatButton(
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.blue, width: 1, style: BorderStyle.solid),
borderRadius: BorderRadius.circular(50),
),
color: Colors.white,
textColor: Colors.black,
onPressed: () {
/*...*/
},
child: Padding(
padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Text(
"Reply",
),
))
])
]))
]);
}
}

Bouncing containers in Listview in flutter

I know enable a button to bounce on tap but the problem i am facing is that i want to implement this on a listview containing containers but i am unable to do it.There are only questions regarding a single button like here https://pub.dev/packages/bouncing_widget but not for whole list of buttons/containers or so. I tried the above link package but it is also causing other issues like the list is not scrolling , and sometimes it is not working at all, Please help
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage()
);
}
}
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin{
AnimationController animationController;
double _scale;
#override
void initState(){
animationController=AnimationController(vsync: this,duration: Duration(milliseconds: 500),
lowerBound: 0.0,upperBound: 0.2);
animationController.addListener(() {
setState(() {
});
});
super.initState();
}
void Ontapdown(TapDownDetails details){
animationController.forward();
}
void Ontapup(TapUpDetails details){
animationController.reverse();
}
bool lights=false;
int count1=0;
int count2=0;
#override
Widget build(BuildContext context) {
_scale =1-animationController.value;
return Scaffold(
appBar: AppBar(
title: Text("Quickier"),
centerTitle: true,
backgroundColor: Colors.indigo,
),
body: Container(
height: 250,
margin: EdgeInsets.fromLTRB(10, 10, 5, 10),
child: ListView(
scrollDirection: Axis.horizontal,
physics: BouncingScrollPhysics(),
children: <Widget>[
GestureDetector(
onTap: (){
Navigator.push(context,MaterialPageRoute(builder:
(context)=> camerapp()));
},
child: Container(
margin: EdgeInsets.fromLTRB(5, 0, 5, 0),
height: 100,
width: 200,
decoration: BoxDecoration(
color: Colors.grey[700],
borderRadius: BorderRadius.all(Radius.circular(10),)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.camera_alt,
color: Colors.black,
size: 70,
),
SizedBox(height: 20.0),
Text(
"Camera",
style: TextStyle(
fontSize: 20.0,
color: Colors.black
),
)
],
)
),
),
GestureDetector(
onTap: (){
setState(() {
if(count1%2==1){
lights=false;
Flashlight.lightOff();}
else{
lights=true;
Flashlight.lightOn();
}
count1+=1;
});
},
child: Container(
margin: EdgeInsets.fromLTRB(5, 0, 5, 0),
height: 100,
width: 200,
padding: EdgeInsets.symmetric(vertical: 20.0,horizontal: 20.0),
decoration: BoxDecoration(
color: Colors.teal[300],
borderRadius: BorderRadius.all(Radius.circular(10),)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.highlight,
color: lights ? Colors.yellow.shade600 : Colors.black,
size: 70,
),
SizedBox(height: 20.0),
Text(
"Flashlight",
style: TextStyle(
fontSize: 20.0,
color: Colors.black
),
)
],
)
),
),
GestureDetector(
onTap: (){
HapticFeedback.lightImpact();
},
onTapDown: Ontapdown,
onTapUp: Ontapup,
child: Transform.scale(
scale: _scale,
child: Container(
margin: EdgeInsets.fromLTRB(5, 0, 5, 0),
height: 100,
width: 200,
decoration: BoxDecoration(
color: Colors.teal[400],
borderRadius: BorderRadius.all(Radius.circular(10),)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.vibration,
color: Colors.black,
size: 70,
),
SizedBox(height: 20.0),
Text(
"Vibration",
style: TextStyle(
fontSize: 20.0,
color: Colors.black
),
)
],
)
),
),
),
Container(
margin: EdgeInsets.fromLTRB(5, 0, 5, 0),
height: 100,
width: 200,
decoration: BoxDecoration(
color: Colors.teal[500],
borderRadius: BorderRadius.all(Radius.circular(10),)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.settings,
color: Colors.black,
size: 70,
),
SizedBox(height: 20.0),
Text(
"Settings",
style: TextStyle(
fontSize: 20.0,
color: Colors.black
),
)
],
)
)
],
),
)
);
}
}
I have enable it on one container i.e. third the vibration one but when i apply ontapup and ontapdown on other's GestureDetectors very different things happen like if i click any one of the containers all are bouncing at the same time,type......
so, please tell me what I should do or if there is any other approach it will be helpful as I'm only a beginner.
Any other suggestions will be grateful too.

Custom Widget GridView

I was trying to perform a "Custom Widget" tutorial, and as you can see my source when I called the custom widget myGridItems(gridName, gridImage, color1, color2) the parameters are underlined, I don't know what did I miss.
import 'package:flutter/material.dart';
import 'package:carousel_pro/carousel_pro.dart';
import 'package:flutter/services.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
return new MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Carousel',
home: ImageCarousel(),
);
}
}
class ImageCarousel extends StatefulWidget {
_ImageCarouselState createState() => new _ImageCarouselState();
}
class _ImageCarouselState extends State<ImageCarousel> with SingleTickerProviderStateMixin {
Animation<double> animation;
AnimationController controller;
initState() {
super.initState();
controller = new AnimationController(
duration: const Duration(milliseconds: 2000), vsync: this);
animation = new Tween(begin: 0.0, end: 18.0).animate(controller)
..addListener(() {
setState(() {
// the state that has changed here is the animation object’s value
});
});
controller.forward();
}
#override
Widget build(BuildContext context) {
double screenHeight = MediaQuery.of(context).size.height;
Widget carousel = new Carousel(
boxFit: BoxFit.cover,
images: [
new AssetImage('assets/s1.jpg'),
new AssetImage('assets/s2.jpg'),
],
animationCurve: Curves.fastOutSlowIn,
animationDuration: Duration(seconds: 1),
);
Widget banner = new Padding(
padding: const EdgeInsets.only(top: 20.0, left: 20.0),
child: new Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15.0),
bottomRight: Radius.circular(15.0)),
color: Colors.amber.withOpacity(0.5),
),
padding: const EdgeInsets.all(10.0),
child: new Text(
'Enter to learn, leave to achieve',
style: TextStyle(
fontFamily: 'fira',
fontSize: animation.value, //18.0,
//color: Colors.white,
),
),
),
// ),
// ),
);
Widget myGridItems (String gridName, String gridImage, int color1, int color2){
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
gradient: new LinearGradient(
colors: [
Color(color1),
Color(color2),
],
begin: Alignment.centerLeft,
end: new Alignment(1.0, 1.0),
)
),
child: Stack(
children: <Widget>[
Opacity(
opacity: 0.3,
child: Container(
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
image: DecorationImage(
image: AssetImage('assets/s1.jpg'),
fit: BoxFit.fill)
),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(child: Text("Job", style: TextStyle(color: Colors.white, fontSize: 16),)),
SizedBox(width: 10.0),
Container(child: Icon(Icons.school, color: Colors.white)),
SizedBox(width: 10.0),
Container(child: Text("Guide", style: TextStyle(color: Colors.white, fontSize: 16),)),
],
),
),
SizedBox(height: 10.0),
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Text(gridName, style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),),
),
],
)
],
),
);
}
return new Scaffold(
appBar: AppBar(
title: Text('Kelden Bilingual Higher Institute of Professional Studies\n'
'Accord N° 18-1020/L/MINSUP/SG/DDES/SD-ESUP/SDA/LMN du 03/12/2018\n'
'Arrêté N° 078/MINEFOP/SG/DFOP/SDGSF/SACD du 13/03/2017', textAlign: TextAlign.center, style: TextStyle(fontSize: 9.5,),),
),
backgroundColor: Colors.blue[200],
body: new Column(
children: <Widget>[
new Container(
padding: const EdgeInsets.fromLTRB(0, 1, 0, 90.0),
height: screenHeight / 2,
child: new ClipRRect(
borderRadius: BorderRadius.circular(0.0),
child: new Stack(
children: [
carousel,
banner,
],
),
),
),
Flexible(
child: GridView.count(
crossAxisCount: 2,
padding: EdgeInsets.all(16.0),
childAspectRatio: 0.9,
crossAxisSpacing: 10.0,
mainAxisSpacing: 10.0,
children: <Widget>[
myGridItems(gridName, gridImage, color1, color2)
],
),
)
],
),
);
}
dispose() {
controller.dispose();
super.dispose();
}
}