Favourite list button on product - flutter

i want to make an this function on the product but i don't know how to since I'm too fresh with flutter...
so here is the picture of how I want it to be
The Sample
and here is my codes.
child: GridTile(
footer: Container(
color: Colors.white,
child: Row(
children: [
Expanded(
flex: 8,
child: Text(product_name),
),
Text("\$$product_price",
style: const TextStyle(fontWeight: FontWeight.w600)),
TextButton(
onPressed: (){
debugPrint('added to cart');
},
child: Text("ADD TO CARD"),
style: TextButton.styleFrom(
primary: Colors.lightBlue[800],
shadowColor: Colors.deepPurple,
// elevation: 5,
),
),
],
),
),
child: Image.asset(
product_picture,
fit: BoxFit.cover,
),
),
),
),
),
and it is how it looks
How it looks
I will appreciate any help!

Here is something similar to the sample
GridView.count(
shrinkWrap: true,
childAspectRatio: .8,
crossAxisCount: 2,
mainAxisSpacing: 4,
crossAxisSpacing: 4,
children: List.generate(10, (index) {
return Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
),
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(5),
child: Image.network('https://i.ytimg.com/vi/6OovMIjDtAM/maxresdefault.jpg',)
),
const SizedBox(height: 14),
const Text('My Drink 101',
style: TextStyle(color: Colors.black, fontSize: 16, fontWeight: FontWeight.w600),
),
const SizedBox(height: 14),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('500 ml', style: TextStyle(color: Colors.black, fontSize: 14, fontWeight: FontWeight.w300)),
Text('\$500 ml', style: TextStyle(color: Colors.black, fontSize: 14, fontWeight: FontWeight.w300)),
],
),
),
const SizedBox(height: 16),
Container(
alignment: Alignment.centerRight,
child: InkWell(
onTap: () {
// add to cart
},
child: Icon(Icons.shopping_cart_outlined, color: Colors.blue,),
),
),
],
),
Align(
alignment: Alignment.topLeft,
child: InkWell(
onTap: () {
// add to favourite
},
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Icon(
Icons.favorite_border,
color: Colors.white,
),
),
),
),
],
),
);
}),
)

Well, there is a bunch needed to make a card similar to the sample you provided. Take a look at this video to get some ideas. I would recommend you to read the flutter widgets documentation for a better understanding of how each property work.
This channel also has a lot of great flutter UI content that is worthy to have a look at.
To start I would consider using a Card instead of a Container

Related

Having trouble recreating this card text?

I cant seem to get this quite right, any ideas how i can replicate this in flutter?
You can see i cant quite get it right
I figured it out.
GestureDetector(
onTap: () => print('feedback'),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Container(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(
right: 15.0),
child: CircleAvatar(
backgroundColor:
AppThemes.mainColorGreen,
radius: 30,
child: Icon(
MdiIcons.commentQuoteOutline,
color: Colors.white,
size: 30,
),
),
),
Flexible(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'Feedback',
style: TextStyle(
fontWeight: FontWeight.bold,
fontFamily: 'Open Sans',
fontSize: 15,
color: Colors.black,
),
),
Text(
'Have any general feedback for our app? Let us know here!'),
],
),
)
],
),
),
),
color: Colors.white,
),
),

Flutter - white spaces displaying for grid view cell in landscape mode

i have a problem to get ride of a white space in grid view cell in fluter, especially when the device is in landscape orientation, the code is :
return Container(
padding: EdgeInsets.only(top: 15),
child: GridView.builder(
itemCount: recipesList.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 0.0,
mainAxisSpacing: 0.0,
//childAspectRatio: 1,
),
itemBuilder: (BuildContext context, int index) {
Recipe recipe = recipesList[index];
return Dismissible(
key: UniqueKey(),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
margin: EdgeInsets.all(8),
color: Colors.white,
elevation: 5,
child: InkWell(
onTap: (){},
child: Column(
// padding: EdgeInsets.zero,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
child: Image.asset(
'images/${recipe.picture}',
height: 200,
width: double.infinity,
fit: BoxFit.cover,
),
),
Container(
padding: EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: Container(
alignment: Alignment.topLeft,
//margin: EdgeInsets.only(left: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${recipe.id} - ${recipe.title}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w500,
),
),
Text(
'by Unknown Chef',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w300,
),
),
Row(
children: [
Icon(
Icons.star,
color: Colors.orange,
size: 20.0,
),
Icon(
Icons.star,
color: Colors.orange,
size: 20.0,
),
Icon(
Icons.star,
color: Colors.orange,
size: 20.0,
),
Icon(
Icons.star,
color: Colors.grey[400],
size: 20.0,
),
Icon(
Icons.star,
color: Colors.grey[400],
size: 20.0,
),
],
)
],
),
),
),
IconButton(
icon: recipe.isFavorite
? Icon(Icons.favorite, color: Colors.red)
: Icon(Icons.favorite_outline_outlined,
color: Colors.grey),
iconSize: 36,
onPressed: (){},
),
],
),
),
],
),
),
),
);
},
),
);
the result is fine as below:
but in landscape mode it's not what i want
the desired result would be like this
How can I make this cards to look like this in landscape orientation?
The default childAspectRatio is 1.0 meaning width = height. If you want to get the expected result, wrap your container in Expanded widget and remove Image height property as following
Expanded(
child: Container(
child: Image.asset(
'images/${recipe.picture}',
width: double.infinity,
fit: BoxFit.cover,
),
),
)

How do I add a splash effect on a card using GestureDetector

I wan't to add splash effect over the card when tapped on it.
I referred some of the answers on stackoverflow but, nothing caught up in my brai. HELP!!
My Code -
body: Container(
padding: EdgeInsets.all(10),
child: ListView(
children: <Widget>[
Container(
height: 100,
child: GestureDetector(
onTap: () {
Navigator.pushNamed(context, '/page1');
},
child: GradientCard(
gradient: LinearGradient(
colors: [Colors.yellow, Colors.lightGreenAccent]),
elevation: 10,
child: Padding(
padding:
const EdgeInsets.symmetric(vertical: 10, horizontal: 8),
child: Center(
child: Row(
children: <Widget>[
SizedBox(width: 25),
Icon(
Icons.favorite,
color: Colors.redAccent,
size: 50,
),
SizedBox(width: 40),
Text(
"MY CARD",
style: TextStyle(fontSize: 28),
),
],
),
),
),
),
),
),
],
),
),
I also tried to wrap onTap: function with InkWell with an ancestor as Material, But it won't let me to do so. Actually, I am confused now and stucked. Any help will be apperiated!!
Try this and let me know if that works!
Container(
padding: EdgeInsets.all(10),
child: ListView(
children: <Widget>[
Container(
height: 100,
child: GradientCard(
gradient: LinearGradient(
colors: [Colors.yellow, Colors.lightGreenAccent]
),
elevation: 10,
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () {
Navigator.pushNamed(context, '/page1');
},
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 8),
child: Center(
child: Row(
children: <Widget>[
SizedBox(width: 25),
Icon(
Icons.favorite,
color: Colors.redAccent,
size: 50,
),
SizedBox(width: 40),
Text(
"MY CARD",
style: TextStyle(fontSize: 28),
),
],
),
),
),
)
)
)
),
],
),
);
Try this:
Container(
height: 100,
child: Material(
elevation: 10,
color: Theme.of(context).cardColor,
child: InkWell(
onTap: () {
Navigator.pushNamed(context, '/page1');
},
child: Center(
child: Row(
children: <Widget>[
SizedBox(width: 25),
Icon(
Icons.favorite,
color: Colors.redAccent,
size: 50,
),
SizedBox(width: 40),
Text(
"MY CARD",
style: TextStyle(fontSize: 28),
),
],
),
),
),
),
)

only static member be accessed in initializers in flutter

I want to try to define below code but when I write it, show me the Error only static member be accessed in initializers, the problem is I can't define it anywhere, the code that I want to define is here, I need to use to calculate discount
double discount=(prod_old_priceprod_old_price-prod_price)/prod_old_price*100;
and this my project code:
class ProductDetails extends StatefulWidget {
final prod_fullName;
final prod_pic;
final prod_old_price;
final prod_price;
ProductDetails({
this.prod_fullName,
this.prod_pic,
this.prod_old_price,
this.prod_price,
});
children: <Widget>[
Expanded(
child: MaterialButton(
onPressed: () {},
color: Colors.white,
textColor: Color(0xff989898),
elevation: 0.2,
child: Row(
children: <Widget>[
Expanded(child: new Text('Color')),
Expanded(child: new Icon(Icons.arrow_drop_down)),
],
),
),
),
Expanded(
child: MaterialButton(
onPressed: () {},
color: Colors.white,
textColor: Color(0xff989898),
elevation: 0.2,
child: Row(
children: <Widget>[
Expanded(child: new Text('Size')),
Expanded(child: new Icon(Icons.arrow_drop_down)),
],
),
),
),
Expanded(
child: MaterialButton(
onPressed: () {},
color: Colors.white,
textColor: Color(0xff989898),
elevation: 0.2,
child: Row(
children: <Widget>[
Expanded(child: new Text('Qty')),
Expanded(child: new Icon(Icons.arrow_drop_down)),
],
),
),
),
],
)
],
),
bottomNavigationBar: Material(
elevation: 7.0,
color: Colors.white,
child: Container(
height: 60.0,
width: MediaQuery.of(context).size.width,
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 10.0),
child: InkWell(
onTap: (){},
child: Container(
height: 40.0,
width: MediaQuery.of(context).size.width - 280.0,
decoration: BoxDecoration(
color: Color(0xffff5f60),
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text(
'add to cart',
style: TextStyle(color: Colors.white,fontSize: 20.0,fontWeight: FontWeight.bold),
),
),
),
),
),
Container(
decoration: BoxDecoration(
color: Color(0xfff40725),
borderRadius: BorderRadius.circular(50),
),
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Text("----------------I WANT USE DISCOUNT HERE --------------------------",style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold),),
),
),
Padding(
padding: const EdgeInsets.only(top:5.0,left:8.0),
child: Container(
child: Column(
children: <Widget>[
Text("\$${widget.prod_old_price}",textAlign: TextAlign.left,style: TextStyle(fontSize: 18.0,color: Color(0xff989898),decoration: TextDecoration.lineThrough),),
Text("\$${widget.prod_price}",style: TextStyle(fontSize: 18.0,fontWeight: FontWeight.bold)),
],
),
),
),
],
),
),
),
);

ClipRRect not working properly using carousel inside listview(scrollview)

I am using a carousel from the package https://pub.dev/packages/carousel_slider, inside my listview (scrollview). I want to make my images have a round corner border.
I used clipRRect and it works (clip corner image with round border). But something strange happens to my apps. Here my result, I upload to google drive, please download first
https://drive.google.com/open?id=1YNRk3q87-wD080eNvLa9OQ1j2KytvaJW
And here my code
class HomeScreen extends StatelessWidget {
Widget menus(){
return Container(
margin: EdgeInsets.symmetric(horizontal: 21, vertical: 18),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Layanan favorit',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w700,
),
),
Text(
'Lihat Semua',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w700,
color: Color(0xFFFF2800)
),
),
],
),
Container(
margin: EdgeInsets.only(top: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconMenu(
text: 'Token Listrik',
image: SvgPicture.asset(ICON_ELECTRICITY),
),
IconMenu(
text: 'Pulsa',
image: SvgPicture.asset(ICON_BALANCE),
),
IconMenu(
text: 'Paket Data',
image: SvgPicture.asset(ICON_DATA),
),
],
),
),
Container(
margin: EdgeInsets.only(top: 28),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconMenu(
text: 'Kereta Api',
image: SvgPicture.asset(ICON_TRAIN),
),
IconMenu(
text: 'e Money',
image: SvgPicture.asset(ICON_EMONEY),
),
IconMenu(
text: 'Pasca Bayar',
image: SvgPicture.asset(ICON_POSTPAID),
),
],
),
)
],
),
);
}
Widget offers(){
return Container(
margin: EdgeInsets.symmetric(vertical: 18),
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(horizontal: 21),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Hot offers',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w700,
),
),
Text(
'Lihat Semua',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w700,
color: Color(0xFFFF2800)
),
),
],
),
),
Container(
margin: EdgeInsets.only(top: 8),
child: CarouselOffers(),
)
],
),
);
}
#override
Widget build(BuildContext context) {
// TODO: implement build
return SafeArea(
child: Scaffold(
appBar: HomeAppBar(),
body: Container(
child: ListView(
children: <Widget>[
Card(
margin: EdgeInsets.fromLTRB(21, 21, 21, 18),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(20, 11, 20, 11),
decoration: BoxDecoration(
borderRadius: new BorderRadius.only(
topLeft: Radius.circular(8.0),
topRight: Radius.circular(8.0)),
color: Theme.of(context).primaryColor
),
child: Row(
children: <Widget>[
Expanded(
child: Container(
child: Text(
'Kasku Balance',
style: TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.w700
),
),
),
),
Container(
margin: EdgeInsets.only(right: 8),
child: Text(
'Rp 2.000.000',
style: TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.w700
)
),
),
Container(
child: GestureDetector(
child: Icon(
Icons.refresh,
color: Colors.white,
),
),
),
],
),
),
Container(
padding: EdgeInsets.only(top: 16, bottom: 16),
decoration: BoxDecoration(
borderRadius: new BorderRadius.only(
bottomLeft: Radius.circular(8.0),
bottomRight: Radius.circular(8.0)),
color: Colors.white
),
child: Row(
children: <Widget>[
Expanded(
child: Column(
children: <Widget>[
Container(
child: SvgPicture.asset(ICON_TOPUP),
),
Container(
margin: EdgeInsets.only(top: 12),
child: Text(
'Isi Saldo',
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 12,
color: Color(0xFF231F20)
),
),
)
],
),
),
Container(
width: 1,
height: 54,
color: Color(0xFFD8D8D8),
),
Expanded(
child: Column(
children: <Widget>[
Container(
child: SvgPicture.asset(ICON_PAY),
),
Container(
margin: EdgeInsets.only(top: 12),
child: Text(
'Bayar',
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 12,
color: Color(0xFF231F20)
),
),
)
],
),
),
Container(
width: 1,
height: 54,
color: Color(0xFFD8D8D8),
),
Expanded(
child: Column(
children: <Widget>[
Container(
child: SvgPicture.asset(ICON_TRANSFER),
),
Container(
margin: EdgeInsets.only(top: 12),
child: Text(
'Transfer',
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 12,
color: Color(0xFF231F20)
),
),
)
],
),
),
],
),
),
],
),
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
),
menus(),
offers(),
news(),
news2()
],
),
),
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
title: Text('Jelajah'),
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
title: Text('Layanan'),
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
title: Text('Transaksi'),
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
title: Text('Profile'),
),
],
type: BottomNavigationBarType.fixed,
),
),
);
}
}
class CarouselOffers extends StatefulWidget{
#override
_CarouselOffersState createState() => _CarouselOffersState();
}
class _CarouselOffersState extends State<CarouselOffers> {
int _current = 0;
List<Widget> widgets(){
return ['https://cdn2.tstatic.net/lampung/foto/bank/images/bukalapak-promo-bulan-ramadan_20180511_135232.jpg', 'https://cdn2.tstatic.net/lampung/foto/bank/images/bukalapak-promo-bulan-ramadan_20180511_135232.jpg'].map((i) {
return Builder(
builder: (BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(horizontal: 5.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image.network(
i,
fit: BoxFit.fill,
),
),
);
},
);
}).toList();
}
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
CarouselSlider(
pauseAutoPlayOnTouch: Duration(seconds: 3),
aspectRatio: 16/6,
items: widgets(),
onPageChanged: (index) {
setState(() {
_current = index;
});
},
autoPlay: true,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: map<Widget>(widgets(), (index, url) {
return Container(
width: 6.0,
height: 6.0,
margin: EdgeInsets.symmetric(vertical: 10.0, horizontal: 4.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: _current == index ? Theme.of(context).primaryColor : Color.fromRGBO(0, 0, 0, 0.4)
),
);
}),
)
],
);
}
}
what is wrong with my code? any ideas?
Sorry for late answer.
Everything is fine when using real device. I do not know why ClipperRRect not working properly when using emulator (Genymotion).