2025-07-30 22:38:44 +07:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
import 'package:enaklo_pos/core/constants/variables.dart';
|
|
|
|
|
import 'package:enaklo_pos/core/extensions/int_ext.dart';
|
|
|
|
|
import 'package:enaklo_pos/presentation/home/bloc/checkout/checkout_bloc.dart';
|
|
|
|
|
import 'package:enaklo_pos/presentation/home/models/product_quantity.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../core/components/spaces.dart';
|
|
|
|
|
import '../../../core/constants/colors.dart';
|
|
|
|
|
|
2025-07-31 23:22:34 +07:00
|
|
|
class OrderMenu extends StatefulWidget {
|
2025-07-30 22:38:44 +07:00
|
|
|
final ProductQuantity data;
|
|
|
|
|
const OrderMenu({super.key, required this.data});
|
|
|
|
|
|
2025-07-31 19:25:45 +07:00
|
|
|
@override
|
2025-07-31 23:22:34 +07:00
|
|
|
State<OrderMenu> createState() => _OrderMenuState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _OrderMenuState extends State<OrderMenu> {
|
|
|
|
|
final _controller = TextEditingController();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_controller.text = widget.data.notes;
|
|
|
|
|
|
|
|
|
|
_controller.addListener(() {
|
|
|
|
|
context.read<CheckoutBloc>().add(
|
|
|
|
|
CheckoutEvent.updateItemNotes(
|
|
|
|
|
widget.data.product,
|
|
|
|
|
_controller.text,
|
2025-07-31 19:25:45 +07:00
|
|
|
),
|
2025-07-31 23:22:34 +07:00
|
|
|
);
|
|
|
|
|
});
|
2025-07-31 19:25:45 +07:00
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:22:34 +07:00
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_controller.dispose();
|
|
|
|
|
super.dispose();
|
2025-07-31 19:25:45 +07:00
|
|
|
}
|
|
|
|
|
|
2025-07-30 22:38:44 +07:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Flexible(
|
|
|
|
|
child: ListTile(
|
|
|
|
|
contentPadding: EdgeInsets.zero,
|
|
|
|
|
leading: ClipRRect(
|
2025-08-03 00:35:00 +07:00
|
|
|
borderRadius: BorderRadius.all(Radius.circular(8.0)),
|
2025-07-30 22:38:44 +07:00
|
|
|
child:
|
|
|
|
|
// Icon(
|
|
|
|
|
// Icons.fastfood,
|
|
|
|
|
// size: 50,
|
|
|
|
|
// color: AppColors.primary,
|
|
|
|
|
// ),
|
|
|
|
|
CachedNetworkImage(
|
2025-08-03 01:00:33 +07:00
|
|
|
imageUrl: (widget.data.product.imageUrl ?? '')
|
|
|
|
|
.contains('http')
|
|
|
|
|
? widget.data.product.imageUrl!
|
|
|
|
|
: '${Variables.baseUrl}/${widget.data.product.imageUrl}',
|
2025-07-30 22:38:44 +07:00
|
|
|
width: 50.0,
|
|
|
|
|
height: 50.0,
|
|
|
|
|
fit: BoxFit.cover,
|
2025-08-03 00:35:00 +07:00
|
|
|
errorWidget: (context, url, error) => Container(
|
|
|
|
|
width: 50.0,
|
|
|
|
|
height: 50.0,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.disabled.withOpacity(0.4),
|
|
|
|
|
),
|
|
|
|
|
child: const Icon(
|
|
|
|
|
Icons.image,
|
|
|
|
|
color: AppColors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-07-30 22:38:44 +07:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
title: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
2025-07-31 23:22:34 +07:00
|
|
|
child: Text(widget.data.product.name ?? "-",
|
|
|
|
|
maxLines: 1,
|
2025-07-30 22:38:44 +07:00
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
subtitle: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
2025-08-04 17:42:39 +07:00
|
|
|
Text((widget.data.product.price! +
|
|
|
|
|
(widget.data.variant?.priceModifier ?? 0))
|
|
|
|
|
.currencyFormatRp),
|
|
|
|
|
if (widget.data.variant != null)
|
|
|
|
|
Text(widget.data.variant?.name ?? ""),
|
2025-07-30 22:38:44 +07:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
GestureDetector(
|
|
|
|
|
onTap: () {
|
2025-08-04 17:42:39 +07:00
|
|
|
context.read<CheckoutBloc>().add(CheckoutEvent.removeItem(
|
|
|
|
|
widget.data.product, widget.data.variant));
|
2025-07-30 22:38:44 +07:00
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 30,
|
|
|
|
|
height: 30,
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
child: const Icon(
|
|
|
|
|
Icons.remove_circle,
|
|
|
|
|
color: AppColors.primary,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: 30.0,
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Text(
|
2025-07-31 23:22:34 +07:00
|
|
|
widget.data.quantity.toString(),
|
2025-07-30 22:38:44 +07:00
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
GestureDetector(
|
|
|
|
|
onTap: () {
|
2025-08-04 17:42:39 +07:00
|
|
|
context.read<CheckoutBloc>().add(
|
|
|
|
|
CheckoutEvent.addItem(
|
|
|
|
|
widget.data.product,
|
|
|
|
|
widget.data.variant,
|
|
|
|
|
),
|
|
|
|
|
);
|
2025-07-30 22:38:44 +07:00
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 30,
|
|
|
|
|
height: 30,
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
child: const Icon(
|
|
|
|
|
Icons.add_circle,
|
|
|
|
|
color: AppColors.primary,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SpaceWidth(8),
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: 80.0,
|
|
|
|
|
child: Text(
|
2025-08-04 17:42:39 +07:00
|
|
|
(widget.data.product.price! * widget.data.quantity +
|
|
|
|
|
(widget.data.variant?.priceModifier ?? 0))
|
2025-07-30 22:38:44 +07:00
|
|
|
.currencyFormatRp,
|
|
|
|
|
textAlign: TextAlign.right,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: AppColors.primary,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2025-07-31 23:22:34 +07:00
|
|
|
SpaceHeight(8.0),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 40,
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Flexible(
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
cursorColor: AppColors.primary,
|
|
|
|
|
controller: _controller,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
color: AppColors.black,
|
|
|
|
|
),
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
hintText: 'Catatan Pesanan',
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SpaceWidth(16.0),
|
2025-08-02 11:06:41 +07:00
|
|
|
GestureDetector(
|
|
|
|
|
onTap: () {
|
2025-08-04 17:42:39 +07:00
|
|
|
context.read<CheckoutBloc>().add(
|
|
|
|
|
CheckoutEvent.deleteItem(
|
|
|
|
|
widget.data.product,
|
|
|
|
|
widget.data.variant,
|
|
|
|
|
),
|
|
|
|
|
);
|
2025-08-02 11:06:41 +07:00
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
height: 40,
|
|
|
|
|
width: 40,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.primary,
|
|
|
|
|
borderRadius: BorderRadius.circular(8.0),
|
|
|
|
|
),
|
|
|
|
|
child: Icon(
|
|
|
|
|
Icons.delete_outline,
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
),
|
2025-07-31 23:22:34 +07:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
2025-07-30 22:38:44 +07:00
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|