app/lib/components/product_box.dart

110 lines
4 KiB
Dart
Raw Normal View History

2022-04-22 22:08:59 +02:00
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
class ProductBox extends StatefulWidget {
2023-11-09 17:48:59 +01:00
const ProductBox(
{Key? key,
required this.imageUrl,
required this.title,
required this.discount,
required this.fontSize,
required this.callback})
: super(key: key);
2022-04-22 22:08:59 +02:00
final String imageUrl;
final String title;
2023-11-09 17:48:59 +01:00
final int discount;
2022-05-13 06:11:14 +02:00
final double fontSize;
2022-04-25 08:48:14 +02:00
final Function() callback;
2022-04-22 22:08:59 +02:00
@override
State<ProductBox> createState() => _ProductBoxState();
}
class _ProductBoxState extends State<ProductBox> {
@override
Widget build(BuildContext context) {
2022-05-13 06:11:14 +02:00
return Container(
margin: const EdgeInsets.all(8.0),
child: Card(
color: const Color(0xff212226),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: InkWell(
onTap: () => widget.callback(),
borderRadius: BorderRadius.circular(10),
2023-11-09 17:48:59 +01:00
child: Stack(
2022-05-13 06:11:14 +02:00
children: [
2023-11-09 17:48:59 +01:00
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
flex: 4,
child: CachedNetworkImage(
imageUrl: widget.imageUrl,
placeholder: (context, url) =>
const CircularProgressIndicator(
color: Color(0xff8B0000),
),
errorWidget: (context, url, error) =>
Image.asset('assets/images/image_error.webp'),
fadeOutDuration: const Duration(milliseconds: 5),
imageBuilder: (context, imageProvider) => Container(
width: 300,
height: 150,
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider, fit: BoxFit.cover)),
),
),
2022-04-23 20:37:25 +02:00
),
2023-11-09 17:48:59 +01:00
Flexible(
flex: 2,
child: Container(
margin: const EdgeInsets.only(top: 10, left: 5, right: 5),
child: Text(
widget.title,
style: TextStyle(
fontSize: widget.fontSize,
color: Colors.white,
fontWeight: FontWeight.w600),
textAlign: TextAlign.center,
),
),
)
],
2022-04-22 22:08:59 +02:00
),
2023-11-09 17:48:59 +01:00
widget.discount != 0
? Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: 50,
height: 20,
decoration: const BoxDecoration(
color: Colors.redAccent,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
bottomLeft: Radius.circular(10.0))),
margin: const EdgeInsets.only(top: 10.0),
child: Center(
2023-11-10 06:43:01 +01:00
child: Text("${widget.discount}% off",
2023-11-09 17:48:59 +01:00
style: const TextStyle(
2023-11-18 10:25:10 +01:00
color: Colors.white,
fontSize: 11.0)))),
2023-11-09 17:48:59 +01:00
],
)
])
: Container(),
2022-05-13 06:11:14 +02:00
],
2022-04-23 20:37:25 +02:00
),
2022-05-13 06:11:14 +02:00
),
),
2022-04-22 22:08:59 +02:00
);
}
}