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>
81 lines
2.8 KiB
Dart
81 lines
2.8 KiB
Dart
part of 'dialog.dart';
|
|
|
|
class VariantDialog extends StatelessWidget {
|
|
final Product product;
|
|
const VariantDialog({super.key, required this.product});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CustomModalDialog(
|
|
title: 'Pilih Varian',
|
|
subtitle: 'Silahkan pilih varian yang sesuai',
|
|
minWidth: context.deviceWidth * 0.4,
|
|
contentPadding: const EdgeInsets.all(16),
|
|
child: Wrap(
|
|
spacing: 12,
|
|
runSpacing: 12,
|
|
crossAxisAlignment: WrapCrossAlignment.start,
|
|
runAlignment: WrapAlignment.start,
|
|
alignment: WrapAlignment.start,
|
|
children: product.variants.map((variant) {
|
|
return GestureDetector(
|
|
onTap: () {
|
|
// Aksi saat varian dipilih
|
|
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
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: Colors.grey.shade300),
|
|
borderRadius: BorderRadius.circular(12),
|
|
color: Colors.white,
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
variant.name,
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
variant.priceModifier.currencyFormatRpV2,
|
|
style: const TextStyle(color: AppColor.black),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
);
|
|
}
|
|
}
|