feat: dukung penjualan produk per timbangan
Produk kini punya cara jual `unit` (cacah) atau `weight` (timbangan), mengikuti kontrak backend di docs/integration-weight-based-products.md. - tipe SellBy, domain/infrastructure unit baru, dan endpoint /api/v1/units - dialog input berat saat produk timbangan ditambahkan ke keranjang - tiap penimbangan jadi baris keranjang sendiri; total baris dihitung berat x harga satuan, sedangkan produk cacah tetap digabung - request ke backend mengirim quantity 1 dan membawa berat - migrasi DB v3: kolom sell_by, unit_id, unit_name, unit_abbreviation di tabel products supaya satuan tetap tampil saat offline - tampilan keranjang, struk, split bill, void, dan refund memakai berat - test/weight_based_products_test.dart menutup perilaku di atas (9 test) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import '../../../application/checkout/checkout_form/checkout_form_bloc.dart';
|
||||
import '../../../common/extension/extension.dart';
|
||||
import '../../../common/theme/theme.dart';
|
||||
import '../../../domain/product/product.dart';
|
||||
import '../dialog/dialog.dart';
|
||||
import '../image/image.dart';
|
||||
import '../spaces/space.dart';
|
||||
|
||||
@@ -26,8 +27,8 @@ class _OrderMenuState extends State<OrderMenu> {
|
||||
|
||||
_controller.addListener(() {
|
||||
context.read<CheckoutFormBloc>().add(
|
||||
CheckoutFormEvent.updateItemNotes(
|
||||
widget.data.product,
|
||||
CheckoutFormEvent.updateLineNotes(
|
||||
widget.data.lineId,
|
||||
_controller.text,
|
||||
),
|
||||
);
|
||||
@@ -40,6 +41,29 @@ class _OrderMenuState extends State<OrderMenu> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _removeLine() {
|
||||
context.read<CheckoutFormBloc>().add(
|
||||
CheckoutFormEvent.removeLine(widget.data.lineId),
|
||||
);
|
||||
}
|
||||
|
||||
/// Koreksi salah timbang: ubah angka pada baris yang sama, bukan menambah
|
||||
/// baris baru.
|
||||
void _editWeight() {
|
||||
final bloc = context.read<CheckoutFormBloc>();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => WeightInputDialog(
|
||||
product: widget.data.product,
|
||||
variant: widget.data.variant,
|
||||
initialWeight: widget.data.weight,
|
||||
onSubmit: (weight) => bloc.add(
|
||||
CheckoutFormEvent.updateItemWeight(widget.data.lineId, weight),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
@@ -77,9 +101,10 @@ class _OrderMenuState extends State<OrderMenu> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
(widget.data.product.price +
|
||||
(widget.data.variant?.priceModifier ?? 0))
|
||||
.currencyFormatRp,
|
||||
widget.data.isWeighted &&
|
||||
widget.data.product.unitLabel.isNotEmpty
|
||||
? '${widget.data.unitPrice.currencyFormatRp} / ${widget.data.product.unitLabel}'
|
||||
: widget.data.unitPrice.currencyFormatRp,
|
||||
),
|
||||
if (widget.data.variant != null)
|
||||
Text(widget.data.variant?.name ?? ""),
|
||||
@@ -87,60 +112,15 @@ class _OrderMenuState extends State<OrderMenu> {
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<CheckoutFormBloc>().add(
|
||||
CheckoutFormEvent.removeItem(
|
||||
widget.data.product,
|
||||
widget.data.variant,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
color: AppColor.white,
|
||||
child: const Icon(
|
||||
Icons.remove_circle,
|
||||
color: AppColor.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 30.0,
|
||||
child: Center(child: Text(widget.data.quantity.toString())),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<CheckoutFormBloc>().add(
|
||||
CheckoutFormEvent.addItem(
|
||||
widget.data.product,
|
||||
widget.data.variant,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
color: AppColor.white,
|
||||
child: const Icon(
|
||||
Icons.add_circle,
|
||||
color: AppColor.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (widget.data.isWeighted)
|
||||
_buildWeightControl()
|
||||
else
|
||||
_buildQuantityStepper(),
|
||||
const SpaceWidth(8),
|
||||
SizedBox(
|
||||
width: 80.0,
|
||||
child: Text(
|
||||
((widget.data.product.price +
|
||||
(widget.data.variant?.priceModifier ?? 0)) *
|
||||
widget.data.quantity)
|
||||
.currencyFormatRp,
|
||||
widget.data.lineTotal.currencyFormatRp,
|
||||
textAlign: TextAlign.right,
|
||||
style: const TextStyle(
|
||||
color: AppColor.primary,
|
||||
@@ -167,14 +147,7 @@ class _OrderMenuState extends State<OrderMenu> {
|
||||
),
|
||||
const SpaceWidth(16.0),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<CheckoutFormBloc>().add(
|
||||
CheckoutFormEvent.removeItem(
|
||||
widget.data.product,
|
||||
widget.data.variant,
|
||||
),
|
||||
);
|
||||
},
|
||||
onTap: _removeLine,
|
||||
child: Container(
|
||||
height: 40,
|
||||
width: 40,
|
||||
@@ -194,4 +167,77 @@ class _OrderMenuState extends State<OrderMenu> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Baris berbobot tidak punya stepper — nilainya bukan cacah, dan angka 1
|
||||
/// yang tersimpan di `quantity` akan terbaca seperti "satu ons".
|
||||
Widget _buildWeightControl() {
|
||||
return GestureDetector(
|
||||
onTap: _editWeight,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.primary.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
border: Border.all(color: AppColor.primary.withOpacity(0.4)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
widget.data.quantityLabel,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColor.primary,
|
||||
),
|
||||
),
|
||||
const SpaceWidth(4),
|
||||
const Icon(Icons.edit_outlined, size: 14, color: AppColor.primary),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQuantityStepper() {
|
||||
return Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<CheckoutFormBloc>().add(
|
||||
CheckoutFormEvent.removeItem(
|
||||
widget.data.product,
|
||||
widget.data.variant,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
color: AppColor.white,
|
||||
child: const Icon(Icons.remove_circle, color: AppColor.primary),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 30.0,
|
||||
child: Center(child: Text(widget.data.quantity.toString())),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<CheckoutFormBloc>().add(
|
||||
CheckoutFormEvent.addItem(
|
||||
widget.data.product,
|
||||
widget.data.variant,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
color: AppColor.white,
|
||||
child: const Icon(Icons.add_circle, color: AppColor.primary),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,18 +17,35 @@ class ProductCard extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (product.isActive == true) {
|
||||
if (product.variants.isEmpty) {
|
||||
context.read<CheckoutFormBloc>().add(
|
||||
CheckoutFormEvent.addItem(product, null),
|
||||
);
|
||||
} else {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => VariantDialog(product: product),
|
||||
);
|
||||
}
|
||||
if (product.isActive != true) return;
|
||||
|
||||
if (product.variants.isNotEmpty) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => VariantDialog(product: product),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Produk timbangan tidak bisa langsung masuk keranjang — kasir harus
|
||||
// menimbang dulu, dan tiap penimbangan jadi barisnya sendiri.
|
||||
if (product.isSoldByWeight) {
|
||||
final bloc = context.read<CheckoutFormBloc>();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => WeightInputDialog(
|
||||
product: product,
|
||||
onSubmit: (weight) => bloc.add(
|
||||
CheckoutFormEvent.addWeightedItem(product, null, weight),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
context.read<CheckoutFormBloc>().add(
|
||||
CheckoutFormEvent.addItem(product, null),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
@@ -75,7 +92,11 @@ class ProductCard extends StatelessWidget {
|
||||
Align(
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
product.price.currencyFormatRp,
|
||||
product.isSoldByWeight
|
||||
? '${product.price.currencyFormatRp} ${product.priceUnitLabel}'
|
||||
.trim()
|
||||
: product.price.currencyFormatRp,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12,
|
||||
@@ -89,31 +110,39 @@ class ProductCard extends StatelessWidget {
|
||||
|
||||
BlocBuilder<CheckoutFormBloc, CheckoutFormState>(
|
||||
builder: (context, state) {
|
||||
final totalQuantity = state.items
|
||||
final lines = state.items
|
||||
.where((item) => item.product.id == product.id)
|
||||
.map((item) => item.quantity)
|
||||
.fold(0, (sum, qty) => sum + qty);
|
||||
.toList();
|
||||
|
||||
if (lines.isEmpty) return const SizedBox.shrink();
|
||||
|
||||
// Untuk produk timbangan, jumlah baris tidak berarti apa-apa
|
||||
// (selalu 1 per penimbangan) — yang informatif adalah total
|
||||
// berat yang sudah masuk keranjang.
|
||||
final label = product.isSoldByWeight
|
||||
? '${lines.fold<double>(0, (sum, item) => sum + (item.weight ?? 0)).weightFormat} ${product.unitLabel}'
|
||||
.trim()
|
||||
: lines
|
||||
.fold<int>(0, (sum, item) => sum + item.quantity)
|
||||
.toString();
|
||||
|
||||
if (totalQuantity == 0) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return Positioned(
|
||||
top: 4,
|
||||
right: 4,
|
||||
child: Container(
|
||||
width: 40,
|
||||
constraints: const BoxConstraints(minWidth: 40),
|
||||
height: 40,
|
||||
padding: const EdgeInsets.all(6),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(9.0)),
|
||||
color: AppColor.primary,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
totalQuantity.toString(),
|
||||
style: const TextStyle(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
fontSize: product.isSoldByWeight ? 13 : 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -24,6 +24,7 @@ import '../spaces/space.dart';
|
||||
part 'custom_modal_dialog.dart';
|
||||
part 'outlet_dialog.dart';
|
||||
part 'variant_dialog.dart';
|
||||
part 'weight_input_dialog.dart';
|
||||
part 'delivery_dialog.dart';
|
||||
part 'order_type_dialog.dart';
|
||||
part 'printer_bluetooth_dialog.dart';
|
||||
|
||||
@@ -163,7 +163,9 @@ class OrderSaveConfirmDialog extends StatelessWidget {
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
'${item.quantity} qty',
|
||||
item.isWeighted
|
||||
? item.quantityLabel
|
||||
: '${item.quantity} qty',
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
),
|
||||
@@ -185,8 +187,7 @@ class OrderSaveConfirmDialog extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
((item.product.price) * item.quantity)
|
||||
.currencyFormatRpV2,
|
||||
item.lineTotal.currencyFormatRpV2,
|
||||
style: AppStyle.md.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColor.primary,
|
||||
|
||||
@@ -21,10 +21,33 @@ class VariantDialog extends StatelessWidget {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
// Aksi saat varian dipilih
|
||||
context.maybePop();
|
||||
context.read<CheckoutFormBloc>().add(
|
||||
CheckoutFormEvent.addItem(product, variant),
|
||||
);
|
||||
final bloc = context.read<CheckoutFormBloc>();
|
||||
// Context dialog ini mati begitu di-pop, jadi dialog lanjutan
|
||||
// dibuka lewat context milik Navigator.
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
navigator.pop();
|
||||
|
||||
// Produk timbangan lanjut ke papan angka; varian hanya mengubah
|
||||
// harga per satuannya.
|
||||
if (product.isSoldByWeight) {
|
||||
showDialog(
|
||||
context: navigator.context,
|
||||
builder: (context) => WeightInputDialog(
|
||||
product: product,
|
||||
variant: variant,
|
||||
onSubmit: (weight) => bloc.add(
|
||||
CheckoutFormEvent.addWeightedItem(
|
||||
product,
|
||||
variant,
|
||||
weight,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
bloc.add(CheckoutFormEvent.addItem(product, variant));
|
||||
},
|
||||
child: Container(
|
||||
width: (context.deviceWidth * 0.4 - 12 - 32) / 2 - 6, // 2 per row
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
part of 'dialog.dart';
|
||||
|
||||
/// Papan angka desimal untuk produk yang dijual per timbangan.
|
||||
///
|
||||
/// Satu kali dialog ini ditutup dengan angka = satu penimbangan = satu baris
|
||||
/// keranjang. Untuk mengoreksi salah timbang, buka lagi baris yang sama lewat
|
||||
/// [initialWeight] alih-alih menambah baris baru.
|
||||
class WeightInputDialog extends StatefulWidget {
|
||||
final Product product;
|
||||
final ProductVariant? variant;
|
||||
final double? initialWeight;
|
||||
final ValueChanged<double> onSubmit;
|
||||
|
||||
const WeightInputDialog({
|
||||
super.key,
|
||||
required this.product,
|
||||
required this.onSubmit,
|
||||
this.variant,
|
||||
this.initialWeight,
|
||||
});
|
||||
|
||||
/// Berat terkecil yang diterima backend; di bawah ini membulat ke nol.
|
||||
static const double minWeight = 0.001;
|
||||
|
||||
/// Backend membulatkan berat ke 3 desimal.
|
||||
static const int maxDecimals = 3;
|
||||
|
||||
@override
|
||||
State<WeightInputDialog> createState() => _WeightInputDialogState();
|
||||
}
|
||||
|
||||
class _WeightInputDialogState extends State<WeightInputDialog> {
|
||||
/// Angka disimpan sebagai teks supaya "4," dan "4,20" bisa diketik utuh
|
||||
/// tanpa dinormalisasi di tengah pengetikan.
|
||||
late String _input = _formatInitial(widget.initialWeight);
|
||||
|
||||
static String _formatInitial(double? weight) {
|
||||
if (weight == null || weight <= 0) return '';
|
||||
return weight
|
||||
.toStringAsFixed(WeightInputDialog.maxDecimals)
|
||||
.replaceFirst(RegExp(r'\.?0+$'), '')
|
||||
.replaceAll('.', ',');
|
||||
}
|
||||
|
||||
double get _weight => double.tryParse(_input.replaceAll(',', '.')) ?? 0;
|
||||
|
||||
bool get _isValid => _weight >= WeightInputDialog.minWeight;
|
||||
|
||||
double get _unitPrice =>
|
||||
widget.product.price + (widget.variant?.priceModifier ?? 0);
|
||||
|
||||
String get _unitLabel => widget.product.unitLabel;
|
||||
|
||||
void _tapDigit(String digit) {
|
||||
final separatorIndex = _input.indexOf(',');
|
||||
if (separatorIndex != -1 &&
|
||||
_input.length - separatorIndex - 1 >= WeightInputDialog.maxDecimals) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
// Hindari "007": nol di depan hanya berarti sesuatu sebelum koma.
|
||||
_input = _input == '0' ? digit : '$_input$digit';
|
||||
});
|
||||
}
|
||||
|
||||
void _tapSeparator() {
|
||||
if (_input.contains(',')) return;
|
||||
setState(() => _input = _input.isEmpty ? '0,' : '$_input,');
|
||||
}
|
||||
|
||||
void _tapBackspace() {
|
||||
if (_input.isEmpty) return;
|
||||
setState(() => _input = _input.substring(0, _input.length - 1));
|
||||
}
|
||||
|
||||
void _tapClear() => setState(() => _input = '');
|
||||
|
||||
void _submit() {
|
||||
if (!_isValid) return;
|
||||
final rounded = double.parse(
|
||||
_weight.toStringAsFixed(WeightInputDialog.maxDecimals),
|
||||
);
|
||||
context.maybePop();
|
||||
widget.onSubmit(rounded);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CustomModalDialog(
|
||||
title: widget.product.name,
|
||||
subtitle: _unitLabel.isEmpty
|
||||
? 'Masukkan berat'
|
||||
: 'Masukkan berat dalam $_unitLabel',
|
||||
minWidth: 380,
|
||||
maxWidth: 420,
|
||||
minHeight: 0,
|
||||
contentPadding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildDisplay(),
|
||||
const SpaceHeight(16),
|
||||
_buildKeypad(),
|
||||
const SpaceHeight(16),
|
||||
AppElevatedButton.filled(
|
||||
borderRadius: 12,
|
||||
disabled: !_isValid,
|
||||
onPressed: _submit,
|
||||
label: widget.initialWeight == null
|
||||
? 'Tambah ke Pesanan'
|
||||
: 'Simpan Berat',
|
||||
),
|
||||
if (_input.isNotEmpty && !_isValid) ...[
|
||||
const SpaceHeight(8),
|
||||
Text(
|
||||
'Berat minimal 0,001${_unitLabel.isEmpty ? '' : ' $_unitLabel'}',
|
||||
textAlign: TextAlign.center,
|
||||
style: AppStyle.sm.copyWith(color: AppColor.error),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDisplay() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.primary.withOpacity(0.06),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColor.primary.withOpacity(0.3)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||
textBaseline: TextBaseline.alphabetic,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
_input.isEmpty ? '0' : _input,
|
||||
textAlign: TextAlign.right,
|
||||
style: AppStyle.xxl.copyWith(
|
||||
fontSize: 40,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _input.isEmpty
|
||||
? AppColor.textSecondary
|
||||
: AppColor.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_unitLabel.isNotEmpty) ...[
|
||||
const SpaceWidth(8),
|
||||
Text(
|
||||
_unitLabel,
|
||||
style: AppStyle.lg.copyWith(color: AppColor.textSecondary),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
const SpaceHeight(4),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'${_unitPrice.currencyFormatRpV2}'
|
||||
'${_unitLabel.isEmpty ? '' : ' / $_unitLabel'}',
|
||||
style: AppStyle.sm.copyWith(color: AppColor.textSecondary),
|
||||
),
|
||||
Text(
|
||||
(_unitPrice * _weight).currencyFormatRpV2,
|
||||
style: AppStyle.lg.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColor.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildKeypad() {
|
||||
const keys = [
|
||||
['1', '2', '3'],
|
||||
['4', '5', '6'],
|
||||
['7', '8', '9'],
|
||||
[',', '0', 'hapus'],
|
||||
];
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
for (final row in keys)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
for (final key in row)
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: _KeypadButton(
|
||||
label: key,
|
||||
onTap: () {
|
||||
switch (key) {
|
||||
case ',':
|
||||
_tapSeparator();
|
||||
case 'hapus':
|
||||
_tapBackspace();
|
||||
default:
|
||||
_tapDigit(key);
|
||||
}
|
||||
},
|
||||
// Tahan lama untuk mengosongkan angka sekaligus.
|
||||
onLongPress: key == 'hapus' ? _tapClear : null,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _KeypadButton extends StatelessWidget {
|
||||
final String label;
|
||||
final VoidCallback onTap;
|
||||
final VoidCallback? onLongPress;
|
||||
|
||||
const _KeypadButton({
|
||||
required this.label,
|
||||
required this.onTap,
|
||||
this.onLongPress,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isBackspace = label == 'hapus';
|
||||
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
onLongPress: onLongPress,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
height: 56,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColor.border),
|
||||
),
|
||||
child: isBackspace
|
||||
? const Icon(Icons.backspace_outlined, color: AppColor.primary)
|
||||
: Text(
|
||||
label,
|
||||
style: AppStyle.xxl.copyWith(fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,7 @@ class PrintUi {
|
||||
bytes += builder.orderItem(
|
||||
productName: item.productName,
|
||||
quantity: item.quantity,
|
||||
quantityLabel: item.isWeighted ? item.quantityLabel : null,
|
||||
unitPrice: item.unitPrice.currencyFormatRpV2,
|
||||
totalPrice: item.totalPrice.currencyFormatRpV2,
|
||||
variantName: item.productVariantName,
|
||||
@@ -140,7 +141,7 @@ class PrintUi {
|
||||
// Items — qty NAMA (uppercase), variant indent
|
||||
for (final item in order.orderItems.where((e) => e.printToChecker)) {
|
||||
final name = item.productName.toUpperCase();
|
||||
bytes += builder.itemText('${item.quantity} $name');
|
||||
bytes += builder.itemText('${item.quantityLabel} $name');
|
||||
if (item.productVariantName.isNotEmpty) {
|
||||
bytes += builder.itemText(' ${item.productVariantName.toUpperCase()}', bold: false);
|
||||
}
|
||||
@@ -196,7 +197,7 @@ class PrintUi {
|
||||
|
||||
// Single item
|
||||
final name = item.productName.toUpperCase();
|
||||
bytes += builder.itemText('${item.quantity} $name');
|
||||
bytes += builder.itemText('${item.quantityLabel} $name');
|
||||
if (item.productVariantName.isNotEmpty) {
|
||||
bytes += builder.itemText(' ${item.productVariantName.toUpperCase()}', bold: false);
|
||||
}
|
||||
@@ -252,7 +253,7 @@ class PrintUi {
|
||||
|
||||
// Single item
|
||||
final name = item.productName.toUpperCase();
|
||||
bytes += builder.itemText('${item.quantity} $name');
|
||||
bytes += builder.itemText('${item.quantityLabel} $name');
|
||||
if (item.productVariantName.isNotEmpty) {
|
||||
bytes += builder.itemText(' ${item.productVariantName.toUpperCase()}', bold: false);
|
||||
}
|
||||
@@ -359,6 +360,7 @@ class PrintUi {
|
||||
bytes += builder.orderItem(
|
||||
productName: item.productName,
|
||||
quantity: item.quantity,
|
||||
quantityLabel: item.isWeighted ? item.quantityLabel : null,
|
||||
unitPrice: item.unitPrice.currencyFormatRpV2,
|
||||
totalPrice: item.totalPrice.currencyFormatRpV2,
|
||||
variantName: item.productVariantName,
|
||||
@@ -439,6 +441,7 @@ class PrintUi {
|
||||
bytes += builder.orderItem(
|
||||
productName: item.productName,
|
||||
quantity: item.quantity,
|
||||
quantityLabel: item.isWeighted ? item.quantityLabel : null,
|
||||
unitPrice: item.unitPrice.currencyFormatRpV2,
|
||||
totalPrice: item.totalPrice.currencyFormatRpV2,
|
||||
variantName: item.productVariantName,
|
||||
@@ -530,6 +533,7 @@ class PrintUi {
|
||||
bytes += builder.orderItem(
|
||||
productName: item.productName,
|
||||
quantity: item.quantity,
|
||||
quantityLabel: item.isWeighted ? item.quantityLabel : null,
|
||||
unitPrice: item.unitPrice.currencyFormatRpV2,
|
||||
totalPrice: item.totalPrice.currencyFormatRpV2,
|
||||
variantName: item.productVariantName,
|
||||
|
||||
@@ -301,6 +301,10 @@ class ReceiptComponentBuilder {
|
||||
List<int> orderItem({
|
||||
required String productName,
|
||||
required int quantity,
|
||||
|
||||
/// Untuk baris berbobot, isi dengan "4,2 ons" — angka quantity-nya selalu
|
||||
/// 1 dan akan salah dibaca di struk.
|
||||
String? quantityLabel,
|
||||
required String unitPrice,
|
||||
required String totalPrice,
|
||||
String? variantName,
|
||||
@@ -314,7 +318,10 @@ class ReceiptComponentBuilder {
|
||||
? '$productName ($variantName)'
|
||||
: productName;
|
||||
bytes += textLeft(displayName, bold: true, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
|
||||
bytes += row2Columns('${quantity}x $unitPrice', totalPrice, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
|
||||
final quantityText = quantityLabel != null && quantityLabel.isNotEmpty
|
||||
? '$quantityLabel x $unitPrice'
|
||||
: '${quantity}x $unitPrice';
|
||||
bytes += row2Columns(quantityText, totalPrice, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
|
||||
if (notes != null && notes.isNotEmpty) {
|
||||
bytes += row2Columns('Note', notes, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth, leftWidth: 4, rightWidth: 8);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import '../../../application/order/order_form/order_form_bloc.dart';
|
||||
import '../../../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart';
|
||||
import '../../../application/table/table_loader/table_loader_bloc.dart';
|
||||
import '../../../common/theme/theme.dart';
|
||||
import '../../../domain/product/product.dart';
|
||||
import '../../../injection.dart';
|
||||
import '../../components/spaces/space.dart';
|
||||
import '../../components/toast/flushbar.dart';
|
||||
@@ -86,14 +87,7 @@ class CheckoutPage extends StatelessWidget implements AutoRouteWrapper {
|
||||
tag: 'checkout_screen',
|
||||
child: BlocBuilder<CheckoutFormBloc, CheckoutFormState>(
|
||||
builder: (context, state) {
|
||||
final price = state.items.fold(
|
||||
0,
|
||||
(previousValue, element) =>
|
||||
previousValue +
|
||||
(element.product.price.toInt() +
|
||||
(element.variant?.priceModifier.toInt() ?? 0)) *
|
||||
element.quantity,
|
||||
);
|
||||
final price = state.items.cartTotal.toInt();
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColor.white,
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../../../application/checkout/checkout_form/checkout_form_bloc.dart';
|
||||
import '../../../../../../common/extension/extension.dart';
|
||||
import '../../../../../../common/theme/theme.dart';
|
||||
import '../../../../../../domain/product/product.dart';
|
||||
import '../../../../../components/button/button.dart';
|
||||
import '../../../../../components/card/order_menu.dart';
|
||||
import '../../../../../components/spaces/space.dart';
|
||||
@@ -21,15 +22,7 @@ class HomeRightPanel extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<CheckoutFormBloc, CheckoutFormState>(
|
||||
builder: (context, state) {
|
||||
final price = state.items.isEmpty
|
||||
? 0.0
|
||||
: state.items
|
||||
.map(
|
||||
(e) =>
|
||||
(e.product.price + (e.variant?.priceModifier ?? 0)) *
|
||||
e.quantity,
|
||||
)
|
||||
.reduce((value, element) => value + element);
|
||||
final price = state.items.cartTotal;
|
||||
log('🛒 Total Price: $price');
|
||||
return Align(
|
||||
alignment: Alignment.topCenter,
|
||||
@@ -87,8 +80,12 @@ class HomeRightPanel extends StatelessWidget {
|
||||
: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
itemBuilder: (context, index) =>
|
||||
OrderMenu(data: state.items[index]),
|
||||
itemBuilder: (context, index) => OrderMenu(
|
||||
// Baris berbobot bisa dihapus satu per satu, jadi
|
||||
// state tiap baris harus terikat ke identitasnya.
|
||||
key: ValueKey(state.items[index].lineId),
|
||||
data: state.items[index],
|
||||
),
|
||||
separatorBuilder: (context, index) =>
|
||||
const SpaceHeight(1.0),
|
||||
itemCount: state.items.length,
|
||||
|
||||
+8
-23
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import '../../../../../../application/checkout/checkout_form/checkout_form_bloc.dart';
|
||||
import '../../../../../../common/extension/extension.dart';
|
||||
import '../../../../../../common/theme/theme.dart';
|
||||
import '../../../../../../domain/product/product.dart';
|
||||
import '../../../../../components/spaces/space.dart';
|
||||
|
||||
class SuccessAddItemOrderRightPanel extends StatelessWidget {
|
||||
@@ -86,14 +87,7 @@ class SuccessAddItemOrderRightPanel extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
Text(
|
||||
(checkoutState.items.fold(
|
||||
0,
|
||||
(previousValue, element) =>
|
||||
previousValue +
|
||||
(element.product.price.toInt() +
|
||||
(element.variant?.priceModifier.toInt() ?? 0)) *
|
||||
element.quantity,
|
||||
)).toString().currencyFormatRpV2,
|
||||
checkoutState.items.cartTotal.toInt().toString().currencyFormatRpV2,
|
||||
style: AppStyle.md.copyWith(fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
@@ -165,15 +159,10 @@ class SuccessAddItemOrderRightPanel extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
(checkoutState.items.fold(
|
||||
0,
|
||||
(previousValue, element) =>
|
||||
previousValue +
|
||||
(element.product.price.toInt() +
|
||||
(element.variant?.priceModifier.toInt() ??
|
||||
0)) *
|
||||
element.quantity,
|
||||
)).toString().currencyFormatRpV2,
|
||||
checkoutState.items.cartTotal
|
||||
.toInt()
|
||||
.toString()
|
||||
.currencyFormatRpV2,
|
||||
style: AppStyle.xl.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
@@ -270,7 +259,7 @@ class SuccessAddItemOrderRightPanel extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
'${item.quantity}x',
|
||||
(item.isWeighted ? item.quantityLabel : "${item.quantity}x"),
|
||||
style: AppStyle.md.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
@@ -279,11 +268,7 @@ class SuccessAddItemOrderRightPanel extends StatelessWidget {
|
||||
),
|
||||
const SpaceHeight(8),
|
||||
Text(
|
||||
((item.product.price.toInt() +
|
||||
(item.variant?.priceModifier.toInt() ?? 0)) *
|
||||
item.quantity)
|
||||
.toString()
|
||||
.currencyFormatRpV2,
|
||||
item.lineTotal.toInt().toString().currencyFormatRpV2,
|
||||
style: AppStyle.lg.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColor.primary,
|
||||
|
||||
+1
-1
@@ -255,7 +255,7 @@ class SuccessOrderRightPanel extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
'${item.quantity}x',
|
||||
(item.isWeighted ? item.quantityLabel : "${item.quantity}x"),
|
||||
style: AppStyle.md.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
|
||||
@@ -211,7 +211,9 @@ class OrderList extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
'x${product.quantity}',
|
||||
(product.isWeighted
|
||||
? product.quantityLabel
|
||||
: "x${product.quantity}"),
|
||||
style: AppStyle.md.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColor.primary,
|
||||
|
||||
+1
-1
@@ -255,7 +255,7 @@ class PaymentSuccessRightPanel extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
'${item.quantity}x',
|
||||
(item.isWeighted ? item.quantityLabel : "${item.quantity}x"),
|
||||
style: AppStyle.md.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
|
||||
+1
-1
@@ -118,7 +118,7 @@ class PaymentSuccessSplitBillRightPanel extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
'${item.quantity}x',
|
||||
(item.isWeighted ? item.quantityLabel : "${item.quantity}x"),
|
||||
style: AppStyle.md.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
|
||||
@@ -65,7 +65,9 @@ class PaymentLeftPanel extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
'Qty: ${item.quantity} | ${item.productVariantName}',
|
||||
item.isWeighted
|
||||
? '${item.quantityLabel} | ${item.productVariantName}'
|
||||
: 'Qty: ${item.quantity} | ${item.productVariantName}',
|
||||
style: AppStyle.sm,
|
||||
),
|
||||
trailing: Text(
|
||||
|
||||
+1
-1
@@ -255,7 +255,7 @@ class RefundSuccessRightPanel extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
'${item.quantity}x',
|
||||
(item.isWeighted ? item.quantityLabel : "${item.quantity}x"),
|
||||
style: AppStyle.md.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
|
||||
@@ -62,7 +62,9 @@ class RefundLeftPanel extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'Qty: ${item.quantity} x Rp ${item.unitPrice.currencyFormatRpV2} ',
|
||||
item.isWeighted
|
||||
? item.quantityPriceLabel
|
||||
: 'Qty: ${item.quantity} x ${item.unitPrice.currencyFormatRpV2}',
|
||||
style: AppStyle.md.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
),
|
||||
|
||||
@@ -160,7 +160,9 @@ class SplitBillLeftPanel extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'Qty: ${item.quantity} x Rp ${item.unitPrice.currencyFormatRpV2} ',
|
||||
item.isWeighted
|
||||
? item.quantityPriceLabel
|
||||
: 'Qty: ${item.quantity} x ${item.unitPrice.currencyFormatRpV2}',
|
||||
style: AppStyle.md.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
),
|
||||
|
||||
@@ -332,97 +332,148 @@ class _SplitBillRightPanelState extends State<SplitBillRightPanel> {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${item.unitPrice.currencyFormatRpV2} per item',
|
||||
item.isWeighted
|
||||
? '${item.unitPrice.currencyFormatRpV2} per ${item.unitLabel}'
|
||||
: '${item.unitPrice.currencyFormatRpV2} per item',
|
||||
style: AppStyle.sm.copyWith(color: AppColor.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (selectedQty > 0) {
|
||||
setState(() {
|
||||
context.read<SplitBillFormBloc>().add(
|
||||
SplitBillFormEvent.itemQuantityChanged(
|
||||
itemId: item.id,
|
||||
quantity: selectedQty - 1,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: selectedQty > 0 ? AppColor.primary : AppColor.border,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.remove,
|
||||
size: 16,
|
||||
color: selectedQty > 0
|
||||
? Colors.white
|
||||
: AppColor.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 40,
|
||||
height: 32,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: AppColor.border),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'$selectedQty',
|
||||
style: AppStyle.md.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColor.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (selectedQty < maxQty) {
|
||||
context.read<SplitBillFormBloc>().add(
|
||||
SplitBillFormEvent.itemQuantityChanged(
|
||||
itemId: item.id,
|
||||
quantity: selectedQty + 1,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: selectedQty < maxQty
|
||||
? AppColor.primary
|
||||
: AppColor.border,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
size: 16,
|
||||
color: selectedQty < maxQty
|
||||
? Colors.white
|
||||
: AppColor.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
// Baris berbobot hanya punya dua keadaan: belum dibayar atau lunas.
|
||||
// Tidak ada nilai di antaranya, jadi stepper diganti tombol pilih.
|
||||
if (item.isWeighted)
|
||||
_buildWeightedLineSelector(item, selectedQty > 0, maxQty)
|
||||
else
|
||||
_buildQuantityStepper(item, selectedQty, maxQty),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWeightedLineSelector(OrderItem item, bool selected, int maxQty) {
|
||||
final canSelect = selected || maxQty > 0;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (!canSelect) return;
|
||||
context.read<SplitBillFormBloc>().add(
|
||||
SplitBillFormEvent.itemQuantityChanged(
|
||||
itemId: item.id,
|
||||
quantity: selected ? 0 : 1,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? AppColor.primary : Colors.transparent,
|
||||
border: Border.all(
|
||||
color: canSelect ? AppColor.primary : AppColor.border,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
selected ? Icons.check_circle : Icons.radio_button_unchecked,
|
||||
size: 16,
|
||||
color: selected ? Colors.white : AppColor.textSecondary,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
selected ? 'Dibayar' : 'Bayar baris',
|
||||
style: AppStyle.sm.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: selected ? Colors.white : AppColor.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQuantityStepper(OrderItem item, int selectedQty, int maxQty) {
|
||||
return Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (selectedQty > 0) {
|
||||
setState(() {
|
||||
context.read<SplitBillFormBloc>().add(
|
||||
SplitBillFormEvent.itemQuantityChanged(
|
||||
itemId: item.id,
|
||||
quantity: selectedQty - 1,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: selectedQty > 0 ? AppColor.primary : AppColor.border,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.remove,
|
||||
size: 16,
|
||||
color: selectedQty > 0 ? Colors.white : AppColor.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 40,
|
||||
height: 32,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: AppColor.border),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'$selectedQty',
|
||||
style: AppStyle.md.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColor.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (selectedQty < maxQty) {
|
||||
context.read<SplitBillFormBloc>().add(
|
||||
SplitBillFormEvent.itemQuantityChanged(
|
||||
itemId: item.id,
|
||||
quantity: selectedQty + 1,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: selectedQty < maxQty ? AppColor.primary : AppColor.border,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
size: 16,
|
||||
color: selectedQty < maxQty
|
||||
? Colors.white
|
||||
: AppColor.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRowButtonSplit() {
|
||||
switch (widget.state.order.splitType) {
|
||||
case 'AMOUNT':
|
||||
@@ -510,7 +561,10 @@ class _SplitBillRightPanelState extends State<SplitBillRightPanel> {
|
||||
splitItems.add(
|
||||
originalItem.copyWith(
|
||||
quantity: quantity,
|
||||
totalPrice: (originalItem.unitPrice) * quantity,
|
||||
// Baris berbobot dibayar penuh; nilainya sudah weight x harga.
|
||||
totalPrice: originalItem.isWeighted
|
||||
? originalItem.totalPrice
|
||||
: (originalItem.unitPrice) * quantity,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,9 @@ class VoidProductCard extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
'Qty: ${item.quantity}',
|
||||
item.isWeighted
|
||||
? item.quantityLabel
|
||||
: 'Qty: ${item.quantity}',
|
||||
style: AppStyle.sm.copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.blue[700],
|
||||
@@ -112,65 +114,13 @@ class VoidProductCard extends StatelessWidget {
|
||||
),
|
||||
|
||||
if (canSelect) ...[
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: AppColor.border),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Decrease Button
|
||||
InkWell(
|
||||
onTap: onTapDecrease,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Icon(
|
||||
Icons.remove,
|
||||
size: 16,
|
||||
color: voidQty > 0
|
||||
? AppColor.primary
|
||||
: Colors.grey[400],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Quantity Display
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
),
|
||||
decoration: const BoxDecoration(
|
||||
border: Border.symmetric(
|
||||
vertical: BorderSide(color: AppColor.border),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'$voidQty',
|
||||
style: AppStyle.sm.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Increase Button
|
||||
InkWell(
|
||||
onTap: onTapIncrease,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
size: 16,
|
||||
color: voidQty < (item.quantity)
|
||||
? AppColor.primary
|
||||
: Colors.grey[400],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Baris berbobot bersifat utuh: dibatalkan seluruhnya atau
|
||||
// tidak sama sekali, jadi yang ditawarkan tombol pilih baris
|
||||
// — bukan stepper jumlah.
|
||||
if (item.isWeighted)
|
||||
_buildLineSelector()
|
||||
else
|
||||
_buildQuantityStepper(),
|
||||
const SpaceWidth(20),
|
||||
],
|
||||
// Price
|
||||
@@ -195,7 +145,7 @@ class VoidProductCard extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
'Void: ${((item.unitPrice) * voidQty).currencyFormatRpV2}',
|
||||
'Void: ${(item.isWeighted ? item.totalPrice : (item.unitPrice) * voidQty).currencyFormatRpV2}',
|
||||
style: AppStyle.sm.copyWith(
|
||||
fontSize: 12,
|
||||
color: AppColor.error,
|
||||
@@ -214,4 +164,97 @@ class VoidProductCard extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Pilih atau lepas satu baris berbobot secara utuh.
|
||||
Widget _buildLineSelector() {
|
||||
final selected = voidQty > 0;
|
||||
|
||||
return InkWell(
|
||||
onTap: selected ? onTapDecrease : onTapIncrease,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? AppColor.primary : Colors.transparent,
|
||||
border: Border.all(
|
||||
color: selected ? AppColor.primary : AppColor.border,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
selected ? Icons.check_circle : Icons.radio_button_unchecked,
|
||||
size: 16,
|
||||
color: selected ? AppColor.white : AppColor.textSecondary,
|
||||
),
|
||||
const SpaceWidth(6),
|
||||
Text(
|
||||
selected ? 'Dipilih' : 'Pilih baris',
|
||||
style: AppStyle.sm.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: selected ? AppColor.white : AppColor.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQuantityStepper() {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: AppColor.border),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Decrease Button
|
||||
InkWell(
|
||||
onTap: onTapDecrease,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Icon(
|
||||
Icons.remove,
|
||||
size: 16,
|
||||
color: voidQty > 0 ? AppColor.primary : Colors.grey[400],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Quantity Display
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: const BoxDecoration(
|
||||
border: Border.symmetric(
|
||||
vertical: BorderSide(color: AppColor.border),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'$voidQty',
|
||||
style: AppStyle.sm.copyWith(fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
|
||||
// Increase Button
|
||||
InkWell(
|
||||
onTap: onTapIncrease,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
size: 16,
|
||||
color: voidQty < (item.quantity)
|
||||
? AppColor.primary
|
||||
: Colors.grey[400],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user