How to make carousel like swipe on stacked cards? - flutter

I am trying to put stack cards on a center view of flutter container.
Which I am trying to have carousel like swipe or slider only left to right or right to left. On right to left the next card will come up and swipe left to right the prvious card will come back. Something like example link to animation
So far, I have gotten the desired view with Stack and Positioned widgets. Now how do I make the slide or animate look like the example?
So far tried to do it with draggable, which is dragging to all around, which is not the behaviour I am looking for. Then I looked at PageView which will not work with Positioned widget as they are expected to be under Stack. So at the moment I am not sure how to do this? Any guide or example would be really helpful, as I just started flutter a week now.
return Scaffold(
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
flex: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SvgPicture.asset(
'assets/images/group_6.svg',
fit: BoxFit.scaleDown,
),
SizedBox(width: 10),
Text(
'My cool Header',
style: TextStyle(
color: const Color(0xFF000000),
fontSize: Constants.height / 70,
fontFamily: 'Exo2',
fontWeight: FontWeight.w600),
),
],
),
),
Expanded(
flex: 13,
child: Stack(
overflow: Overflow.visible,
alignment: Alignment.center,
children: <Widget>[
Positioned(
right: (sizingInformation.screenSize.width * 0.09),
left: (sizingInformation.screenSize.width * 0.21),
child: Card(
color: Colors.blue,
elevation: 10.0,
child: Container(
height: (sizingInformation.screenSize.height * 0.5),
),
),
),
Positioned(
right: sizingInformation.screenSize.width * 0.15,
left: sizingInformation.screenSize.width * 0.15,
child: Card(
color: Colors.red,
elevation: 10.0,
child: Container(
height: (sizingInformation.screenSize.height * 0.55),
),
),
),
],
),
),
Expanded(
flex: 2,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Some cool text',
style: TextStyle(
color: const Color(0xFF000000),
fontSize: Constants.height / 70,
fontFamily: 'Exo2',
fontWeight: FontWeight.w600,
),
),
Text(
'Some cool text',
style: TextStyle(
color: const Color(0xFF000000),
fontSize: Constants.height / 70,
fontFamily: 'Exo2',
fontWeight: FontWeight.w600),
),
]),
),
Expanded(
flex: 3,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// Search
IconButton(
icon: SvgPicture.asset(
'assets/images/group_9.svg',
fit: BoxFit.contain,
),
onPressed: () {
widget.comingFromLogin
? Navigator.push(context,
SlideRightRoute(page: SearchFoodPage()))
: _loginPopUp();
}),
// Add Event
IconButton(
icon: SvgPicture.asset(
'assets/images/group_26.svg',
fit: BoxFit.contain,
),
onPressed: () {
widget.comingFromLogin
? Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Events()))
: _loginPopUp();
},
),
// Profile
IconButton(
icon: SvgPicture.asset(
'assets/images/group_8.svg',
fit: BoxFit.contain,
),
onPressed: () {
widget.comingFromLogin
? Navigator.push(context,
SlideLeftRoute(page: ProfileDrawer()))
: _loginPopUp();
}),
],
),
),
]),
),
);

Is it something like this library: flutter_swiper, stack layout
Swiper(
itemBuilder: (BuildContext context, int index) {
return new Image.network(
"http://via.placeholder.com/288x188",
fit: BoxFit.fill,
);
},
itemCount: 10,
itemWidth: 300.0,
layout: SwiperLayout.STACK,
)

Related

How to fill a second container color?

I have this design:
And I want that the bottom of the container also have a pink color, something like this:
This is my code:
LayoutBuilder(
builder: (context, constraints) {
return Scaffold(
backgroundColor: Color(0xffF6F6F6),
body: TextSelectionTheme(
data: TextSelectionTheme.of(context).copyWith(
selectionColor: Color(0xffD7D7D7),
cursorColor: Color(0xff3B3B3B),
selectionHandleColor: Color(0xffD7D7D7),
),
child: Center(
child: Container(
height: double.maxFinite,
width: double.maxFinite,
decoration: BoxDecoration(
color: Color(0xffF6F6F6),
borderRadius: BorderRadius.all(
Radius.circular(0.0),
),
),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RichText(
text: TextSpan(
style: GoogleFonts.questrial(),
children: [
WidgetSpan(
child: Icon(FontAwesomeIcons.checkDouble,
size: 40,
color: Color(0xffD7D7D7)),
),
],
),
),
RichText(
text: TextSpan(
style: GoogleFonts.questrial(),
children: [
WidgetSpan(
child: GestureDetector(
onTap: () {
showDialog(
context: context,
barrierColor: Colors.transparent,
builder: (ctx) => HomePagePomodoroTimer());
},
child: Icon(FontAwesomeIcons.squareXmark,
size: 40,
color: Color(0xff3B3B3B),),
),
),
],
),
),
],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: Container(
decoration: BoxDecoration(
color: Color(0xffF4CFDD),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(50, 30, 50, 0),
child: Column(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"We send you an Email",
style: TextStyle(
fontSize: 20,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: Color(0xff3B3B3B),
),
),
],
),
SizedBox(height: 50,),
const Center(
child: Text(
"Please, check your Email inbox to log in and start using Pomoworko",
style: TextStyle(
fontSize: 20,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: Color(0xff3B3B3B),
),
),
),
Divider(color: Color(0xff3B3B3B)),
SizedBox(height: 40,),
const SizedBox(height: 360,
child: RiveAnimation.asset('letter_and_knife.riv',
fit: BoxFit.cover
),),
],
),
),
),
),
],
)
],
),
),
),
),
),
);
}
)
If I add this piece of code to the pink container:
Center(
child: Container(
height: double.maxFinite,
decoration: BoxDecoration(
color: Color(0xffF4CFDD), //pink color
),
I got this:
How to solve this issue?
It is possible to add a second container at the same time or not?
Thank you in advance
The problem is that you are using height: double.maxFinite with returns constant value of 1.7976931348623157e+308, in that case you want the size of your current widget parent context simple use MediaQuery.of(context).size.height
the code should look like this:
Center(
child: Container(
height: MediaQuery.of(context).size.height,
decoration: const BoxDecoration(
color: Color(0xffF4CFDD),
),
Consider giving the two children equal height or height you would want them to have from the constraints using SizedBox or Container like below.
LayoutBuilder(
builder: (context, constraints) {
return Column(
children: [
Container(
height: constraints.maxHeight/2, width: double.infinity, color: Colors.red,
),
Container(
height: constraints.maxHeight/2, width: double.infinity, color: Colors.red,
),
]
);
});
This way now you can move the children you want inside those containers.
Note: SingleChildScrollView does not work with infinite constraints children like Column on infinite height, consider sizing them or setting MainAxisSize.min or Flexible instead of constraints.

flutter problem: How to make button with centered text and right side Icon

I want to make a button, In this button I want a text and icon both but text should be in center and icon will be right side.
this is code of button.
bottomNavigationBar: Padding(
padding:
const EdgeInsets.only(top: 20.0, bottom: 20, left: 20, right: 20),
child: SizedBox(
height: 45,
width: MediaQuery.of(context).size.width,
child: FlatButton(
onPressed: () {
_controller.nextPage(
duration: const Duration(milliseconds: 200),
curve: Curves.easeIn,
);
if(_currentPage + 1 == splashData.length){
Navigator.push(context,
MaterialPageRoute(builder: (context) => HomePage()));
}
},
child: Row(mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Next",
style: TextStyle(
fontSize: 14,
color: Colors.white,
),
),
SizedBox(width: 50,),
Padding(
padding: const EdgeInsets.only(right: 10),
child: Icon(Icons.arrow_forward,color: whiteColor,),
)
],
),
color: skyBlue,
),
),
),
I want like this button
but is becoming like this.
Try below code, used Opacity widget and set opacity:0
Note: Don't used FlatButton its depricated by Flutter used instead of ElevatedButton, TextButton
Refer here to new buttons
ElevatedButton(
onPressed: () {
//write your onPressed function here
print('Pressed');
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Opacity(
opacity: 0,
child: Icon(Icons.arrow_forward),
),
Text('Next'),
Icon(Icons.arrow_forward),
],
),
),
Your result screen->
You can use Stack instead of Row to achieve easily.
Inside Stack you can use Positioned(right: 10, child: Icon()) also.
Stack(
alignment: Alignment.center,
children: const [
Text(
'Next',
style: TextStyle(
fontSize: 14,
color: Colors.white,
),
),
Align(
alignment: Alignment.centerRight,
child: Icon(Icons.arrow_forward, color: Colors.white,),
)
],
)
We have more than two ways to achieve it. I have given two easiest option to achieve it.
You can use Expanded (and play with the flex property if needed).
Also add an Align
For instance:
Row(mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(),
Expanded(
child: Text(
"Next",
style: TextStyle(
fontSize: 14,
color: Colors.white,
),
),
),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: 10),
child: Icon(Icons.arrow_forward,color: whiteColor),
),
),
),
],
),

flutter alertdialog with background image

Folloing is my alert dialog box code, i need to set an background image for the alert dialog instead of blue color, need to show a design
AlertDialog(
backgroundColor: Colors.blue,
titlePadding: EdgeInsets.all(0),
contentPadding: EdgeInsets.all(0),
title: Container(
decoration: BoxDecoration(
color: profile_edit_toolbar_color,
borderRadius: BorderRadius.all(Radius.circular(8))),
width: MediaQuery.of(context).size.width * 0.7,
height: MediaQuery.of(context).size.height * 0.5,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.all(18),
child: Text(
'Select countries to show',
style: TextStyle(
color: Colors.yellow[300],
fontSize: 20,
fontFamily: fontFamily_3),
// style: CustomStyle.balooCustom(20, Colors.white)
),
),
IconButton(
onPressed: () {
Navigator.of(context).pop();
},
icon: Icon(
Icons.close,
size: 25,
color: Colors.white,
)),
],
),
Row(
children: [
Expanded(
child: Container(
height: 120,
child: DisplayCountriesForm(
countriesList: eventResponse.countriesList,
num: 0,
displayCountries: displayCountries,
onValueChanged: (updatedList) {
},
),
)),
Expanded(
child: Container(
height: 120,
child: DisplayCountriesForm(
countriesList: eventResponse.countriesList,
num: 1,
displayCountries: displayCountries,
onValueChanged: (updatedList) {
},
),
)),
Expanded(
child: Container(
height: 120,
child: DisplayCountriesForm(
countriesList: eventResponse.countriesList,
num: 2,
displayCountries: displayCountries,
onValueChanged: (updatedList) {
},
),
)),
],
),
],
),
),
);
Try below code I have add background image of the alert dialog hope your problem is solved , Use your widget also and change background image on your need
TextButton(
child: Text('Pressed Me'),
onPressed: () => showDialog(
context: context,
builder: (context) => AlertDialog(
content: Stack(
alignment: Alignment.center,
children: <Widget>[
Image.network(
'https://www.kindpng.com/picc/m/355-3557482_flutter-logo-png-transparent-png.png',
),
Text(
'Add Your Text Here',
style: TextStyle(
fontSize: 24,
),
),
],
),
),
),
),
Your Result Screen->

How to Position Widgets Independently of Other Widgets in flutter?

I was Trying to Have 3 Widgets in Single page using Column, but for some reason the alignment is not working...
#override
Widget build(BuildContext context) {
return Container(
height: double.infinity,
child: SwipeDetector(
onSwipeUp: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CreditScreen()));
},
onSwipeDown: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ManualScreen()));
},
child: Scaffold(
backgroundColor: DarkBlue,
resizeToAvoidBottomInset: false,
body: new Container(
height: double.infinity,
alignment: Alignment.center,
child: Column(
//mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Align(
alignment: Alignment.topCenter,
child: Image.asset('assets/swipe_down.gif',
scale: 5,
),
),
new Align(
alignment: Alignment.center,
child: Text("Menu Screen",
style: TextStyle(
color: Colors.white,
fontSize: 30.0,
fontWeight: FontWeight.bold,
),
//textAlign: TextAlign.center,
),
),
new Align(
alignment: Alignment.bottomCenter,
child: Image.asset('assets/swipe_up.gif',
scale: 5,
),
),
],
),
),
),
),
);
}
}
According to the above image, I want the swipe up widget at bottom and swipe down at the top while the text in center, I Tried Many wrapping of Widgets, but nothing seems to work...
Any Help...
try this:
Column(
//mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/swipe_down.gif',
scale: 5,
),
Expanded(
child: Text("Menu Screen",
style: TextStyle(
color: Colors.white,
fontSize: 30.0,
fontWeight: FontWeight.bold,
),
//textAlign: TextAlign.center,
),
),
Image.asset('assets/swipe_up.gif',
scale: 5,
),
],
),
You can use Center widget for aligning widgets in center along with padding widget for giving spaces between the widgets.
Scaffold(
backgroundColor: Colors.black,
resizeToAvoidBottomInset: false,
body: new Container(
height: double.infinity,
alignment: Alignment.center,
child:
Center(
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top:30),
child: Image.asset('assets/swipe_down.gif'),
),
Padding(
padding: EdgeInsets.only(top:80),
child:
Text("Menu Screen",
style: TextStyle(
color: Colors.white,
fontSize: 30.0,
fontWeight: FontWeight.bold
),
),
),
Padding(
padding: EdgeInsets.only(top:80),
child: Image.asset('assets/swipe_up.gif'),
),
],
),
),
),
),

I want to make Responsive appbar in flutter. According to the design that I have

This is the design of appbar that I want to create using flutter and that should be responsive for all types of mobile devices and Tablets. Please let me know what to do to achieve this.
Widget _buildHeader() {
return Container(
height: MediaQuery.of(context).size.height* .22,
width: MediaQuery.of(context).size.width * 1,
color: Color(0xFF0A182E),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 10, top: 40),
child: FlatButton(
onPressed: () {
print("homebtn clicked..!!"); //Home button
},
child: Text(
"Home",
style: TextStyle(
color: Colors.white,
fontSize: 30,
fontWeight: FontWeight.bold),
),
),
),
SizedBox(width: MediaQuery.of(context).size.width *.47,),
FlatButton(
onPressed: () {
print("profilebtn clicked");
},
shape: CircleBorder(),
child: Container(
margin: EdgeInsets.only(top: 20),
height: MediaQuery.of(context).size.height*.07,
width: MediaQuery.of(context).size.width*.14,
child: CircleAvatar(
backgroundImage: AssetImage("images/profilebtn.png"),
),
),
),
],
),
SizedBox(height: MediaQuery.of(context).size.height * .04,),
Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 10),
child: FlatButton(
onPressed: () {
print("Roomsbtn clicked.!");
},
child: Container(
child: Text(
"ROOMS",
style: TextStyle(
fontSize: 20,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
),
),
FlatButton(
onPressed: () {
print("Devicesbtn clicked.!");
},
child: Container(
child: Text(
"DEVICES",
style: TextStyle(
fontSize: 20,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
),
SizedBox(width: MediaQuery.of(context).size.width *.27,),
Transform.scale( //add Button
scale: .65,
child: FloatingActionButton(
onPressed: () {
print("Redplusbtn clicked.!");
_onButtonPressed();
},
child: Icon(
Icons.add,
size: 45,
),
backgroundColor: Colors.red,
),
),
],
),
],
),
);
}
This is what I have tried but I find this approach is lengthy and not responsive.I have tried in other devices and appbar is not responsive so I want to make this appbar in a Standard way.
I think this is way better solution. First of all there is no need to call media query to find a width and height. Another thing is that you can use AppBar widget and rework it to the way you like. Look at this example and amend it to your needs..
Scaffold(
appBar: AppBar(
title: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[Text('Hello'), Icon(Icons.email)],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Text('Option1'),
Text('Option2'),
],
),
Icon(Icons.language)
],
)
],
),
),
body: Container())
I would try putting the higher elements (title and picture) on the AppBar and the lower elements (Room, devices and plus icon) on a TabBar.
AppBar: https://api.flutter.dev/flutter/material/AppBar-class.html
TabBar: https://api.flutter.dev/flutter/material/TabBar-class.html
You can identify the customer device first using this plugin https://pub.dev/packages/device_info
the next steps, you can set the condition of the appbar in each device.
for more details you can check this link https://iiro.dev/2018/01/28/implementing-adaptive-master-detail-layouts/