Skip to content

Instantly share code, notes, and snippets.

@eudson
Created May 4, 2023 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eudson/30a2116fa069218a2ee4108f5a00ec15 to your computer and use it in GitHub Desktop.
Save eudson/30a2116fa069218a2ee4108f5a00ec15 to your computer and use it in GitHub Desktop.
Pagamio: Product Card
import 'package:flutter/material.dart';
import 'package:pagamio/common/utils.dart';
import 'package:pagamio/data/provider/cart_provider.dart';
import 'package:provider/provider.dart';
import '../../constants.dart';
import '../network_image_with_loader.dart';
class ProductCard extends StatelessWidget {
const ProductCard(
{Key? key,
required this.image,
required this.brandName,
required this.title,
required this.price,
this.priceAfetDiscount,
this.dicountpercent,
required this.press,
this.cartCount,
this.productId,
this.disableDecrement})
: super(key: key);
final String image, brandName, title;
final double price;
final double? priceAfetDiscount;
final int? dicountpercent;
final int? cartCount;
final int? productId;
final bool? disableDecrement;
final VoidCallback press;
@override
Widget build(BuildContext context) {
return OutlinedButton(
onPressed: press,
style: OutlinedButton.styleFrom(
minimumSize: const Size(140, 96),
maximumSize: const Size(140, 96),
side: cartCount != null && cartCount! > 0
? const BorderSide(color: Colors.green, width: 1)
: null,
padding: const EdgeInsets.all(2)),
child: Column(
children: [
AspectRatio(
aspectRatio: 1.15,
child: Stack(
children: [
NetworkImageWithLoader(image, radius: defaultBorderRadious),
if (cartCount != null && cartCount! > 0)
Positioned(
right: 0,
top: 0,
child: RemoveFromCartButton(
productId: productId!,
count: cartCount,
disableDecrement: disableDecrement,
),
),
if (dicountpercent != null)
Positioned(
right: defaultPadding / 2,
top: defaultPadding / 2,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: defaultPadding / 2),
height: 16,
decoration: const BoxDecoration(
color: errorColor,
borderRadius: BorderRadius.all(
Radius.circular(defaultBorderRadious)),
),
child: Text(
"$dicountpercent% off",
style: const TextStyle(
color: Colors.white,
fontSize: 10,
fontWeight: FontWeight.w500),
),
),
)
],
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: defaultPadding / 2, vertical: defaultPadding / 2),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
brandName.toUpperCase(),
style: Theme.of(context)
.textTheme
.bodyText2!
.copyWith(fontSize: 10),
),
const SizedBox(height: defaultPadding / 2),
Text(
Utils.trimString(title),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.subtitle2!
.copyWith(fontSize: 16),
),
const Spacer(),
priceAfetDiscount != null
? Row(
children: [
Text(
"R " + priceAfetDiscount.toString(),
style: const TextStyle(
color: Color(0xFF31B0D8),
fontWeight: FontWeight.w500,
fontSize: 14,
),
),
const SizedBox(width: defaultPadding / 4),
Text(
"R " + price.toString(),
style: TextStyle(
color: Theme.of(context)
.textTheme
.bodyText2!
.color,
fontSize: 10,
decoration: TextDecoration.lineThrough,
),
),
],
)
: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"R " + Utils.formatPrice(price),
style: const TextStyle(
color: Color(0xFF31B0D8),
fontWeight: FontWeight.w500,
fontSize: 16,
),
),
// if (cartCount != null && cartCount! > 0)
// RemoveFromCartButton(
// productId: productId!,
// count: cartCount,
// disableDecrement: disableDecrement,
// )
],
)
],
),
),
),
],
),
);
}
}
class RemoveFromCartButton extends StatelessWidget {
const RemoveFromCartButton(
{Key? key, required this.productId, this.count, this.disableDecrement})
: super(key: key);
final int productId;
final int? count;
final bool? disableDecrement;
@override
Widget build(BuildContext context) {
return TextButton(
onPressed: () => disableDecrement == true
? null
: Provider.of<CartProvider>(context, listen: false)
.removeFromCart(productId),
style: OutlinedButton.styleFrom(
minimumSize: const Size(24, 20),
backgroundColor: errorColor,
shape: const StadiumBorder(),
padding: const EdgeInsets.symmetric(
vertical: defaultPadding / 4, horizontal: defaultPadding),
),
child: Text(
count.toString(),
style: const TextStyle(color: Colors.white),
),
// child: SvgPicture.asset(
// "assets/icons/Minus.svg",
// height: 20,
// width: 20,
// color: Colors.white,
// ),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment