2025-07-30 22:38:44 +07:00
|
|
|
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2025-07-31 20:58:10 +07:00
|
|
|
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
|
2025-08-01 01:40:33 +07:00
|
|
|
import 'package:enaklo_pos/presentation/setting/dialogs/detail_product_dialog.dart';
|
2025-07-30 22:38:44 +07:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:enaklo_pos/data/models/response/product_response_model.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../core/components/buttons.dart';
|
|
|
|
|
import '../../../core/components/spaces.dart';
|
|
|
|
|
import '../../../core/constants/colors.dart';
|
|
|
|
|
import '../../../core/constants/variables.dart';
|
|
|
|
|
|
|
|
|
|
class MenuProductItem extends StatelessWidget {
|
|
|
|
|
final Product data;
|
|
|
|
|
final Function() onTapEdit;
|
2025-07-31 20:58:10 +07:00
|
|
|
const MenuProductItem(
|
|
|
|
|
{super.key, required this.data, required this.onTapEdit});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Container(
|
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
borderRadius: BorderRadius.circular(12.0),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0).copyWith(bottom: 0),
|
|
|
|
|
child: Stack(
|
|
|
|
|
children: [
|
|
|
|
|
AspectRatio(
|
|
|
|
|
aspectRatio: 1.2,
|
|
|
|
|
child: ClipRRect(
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
child: CachedNetworkImage(
|
2025-08-03 00:35:00 +07:00
|
|
|
imageUrl: data.name!.contains('http')
|
|
|
|
|
? data.name!
|
|
|
|
|
: '${Variables.baseUrl}/${data.name}',
|
2025-07-31 20:58:10 +07:00
|
|
|
fit: BoxFit.cover,
|
|
|
|
|
errorWidget: (context, url, error) => Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
height: context.deviceHeight * 0.18,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.grey.withOpacity(0.1),
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
),
|
|
|
|
|
child: const Icon(
|
|
|
|
|
Icons.image_outlined,
|
|
|
|
|
color: AppColors.grey,
|
|
|
|
|
size: 40,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Positioned(
|
|
|
|
|
top: 8,
|
|
|
|
|
right: 8,
|
|
|
|
|
child: Container(
|
|
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.primary,
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
2025-08-03 00:35:00 +07:00
|
|
|
"",
|
2025-07-31 20:58:10 +07:00
|
|
|
style: const TextStyle(
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Text(
|
|
|
|
|
"${data.name}",
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
fontWeight: FontWeight.w700,
|
|
|
|
|
),
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: GestureDetector(
|
2025-08-01 01:40:33 +07:00
|
|
|
onTap: () => showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) => DetailProductDialog(product: data),
|
|
|
|
|
),
|
2025-07-31 20:58:10 +07:00
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.primary,
|
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
|
bottomLeft: Radius.circular(12),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Icon(
|
|
|
|
|
Icons.visibility_outlined,
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
size: 18,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
width: 1,
|
|
|
|
|
color: AppColors.grey.withOpacity(0.2),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: GestureDetector(
|
|
|
|
|
onTap: onTapEdit,
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.primary,
|
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
|
bottomRight: Radius.circular(12),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Icon(
|
|
|
|
|
Icons.edit_outlined,
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
size: 18,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MenuProductItemOld extends StatelessWidget {
|
|
|
|
|
final Product data;
|
|
|
|
|
final Function() onTapEdit;
|
|
|
|
|
const MenuProductItemOld({
|
2025-07-30 22:38:44 +07:00
|
|
|
super.key,
|
|
|
|
|
required this.data,
|
|
|
|
|
required this.onTapEdit,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Container(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
decoration: ShapeDecoration(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
side: const BorderSide(width: 3, color: AppColors.blueLight),
|
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: buildList(context),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Widget> buildList(BuildContext context) {
|
|
|
|
|
return [
|
|
|
|
|
Stack(
|
|
|
|
|
children: [
|
|
|
|
|
Center(
|
|
|
|
|
child: ClipRRect(
|
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(10.0)),
|
|
|
|
|
child: CachedNetworkImage(
|
2025-08-03 00:35:00 +07:00
|
|
|
imageUrl: '${Variables.baseUrl}/${data.name}',
|
2025-07-30 22:38:44 +07:00
|
|
|
placeholder: (context, url) =>
|
|
|
|
|
const Center(child: CircularProgressIndicator()),
|
|
|
|
|
errorWidget: (context, url, error) => const Icon(
|
|
|
|
|
Icons.food_bank_outlined,
|
|
|
|
|
size: 80,
|
|
|
|
|
),
|
|
|
|
|
width: 54,
|
|
|
|
|
height: 54,
|
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
Flexible(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Spacer(),
|
|
|
|
|
Text(
|
|
|
|
|
data.name!,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
),
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
Text(
|
2025-08-03 00:35:00 +07:00
|
|
|
'-',
|
2025-07-30 22:38:44 +07:00
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Spacer(),
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Flexible(
|
|
|
|
|
child: Button.outlined(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
// backgroundColor: AppColors.white,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
//container for product detail
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
contentPadding: const EdgeInsets.all(16.0),
|
|
|
|
|
content: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment:
|
|
|
|
|
MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
data.name!,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
},
|
|
|
|
|
icon: const Icon(Icons.close),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SpaceHeight(10.0),
|
|
|
|
|
ClipRRect(
|
|
|
|
|
borderRadius: const BorderRadius.all(
|
|
|
|
|
Radius.circular(10.0)),
|
|
|
|
|
child: CachedNetworkImage(
|
|
|
|
|
imageUrl:
|
2025-08-03 00:35:00 +07:00
|
|
|
'${Variables.baseUrl}${data.name}',
|
2025-07-30 22:38:44 +07:00
|
|
|
placeholder: (context, url) =>
|
|
|
|
|
const Center(
|
|
|
|
|
child:
|
|
|
|
|
CircularProgressIndicator()),
|
|
|
|
|
errorWidget: (context, url, error) =>
|
|
|
|
|
const Icon(
|
|
|
|
|
Icons.food_bank_outlined,
|
|
|
|
|
size: 80,
|
|
|
|
|
),
|
|
|
|
|
width: 80,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SpaceHeight(10.0),
|
|
|
|
|
Text(
|
2025-08-03 00:35:00 +07:00
|
|
|
'-',
|
2025-07-30 22:38:44 +07:00
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SpaceHeight(10.0),
|
|
|
|
|
Text(
|
|
|
|
|
data.price.toString(),
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SpaceHeight(10.0),
|
|
|
|
|
Text(
|
2025-08-03 00:35:00 +07:00
|
|
|
"data.stock.toString()",
|
2025-07-30 22:38:44 +07:00
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SpaceHeight(10.0),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
label: 'View',
|
|
|
|
|
fontSize: 12.0,
|
|
|
|
|
height: 30,
|
|
|
|
|
borderRadius: 10,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SpaceWidth(6.0),
|
|
|
|
|
Flexible(
|
|
|
|
|
child: Button.outlined(
|
|
|
|
|
onPressed: onTapEdit,
|
|
|
|
|
label: 'Edit',
|
|
|
|
|
fontSize: 12.0,
|
|
|
|
|
height: 30,
|
|
|
|
|
borderRadius: 10,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|