93 lines
2.6 KiB
Dart
93 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import 'package:intl/intl.dart'; // Untuk format angka
|
|
import 'package:cashumit/models/receipt_item.dart';
|
|
|
|
/// Widget untuk menampilkan satu item dalam struk.
|
|
///
|
|
/// Widget ini murni untuk tampilan dan tidak memiliki logika interaksi sendiri.
|
|
/// Interaksi seperti tap (edit) atau long-press (delete) ditangani oleh
|
|
/// widget induk (parent) yang membungkusnya dalam GestureDetector.
|
|
class ReceiptItemWidget extends StatelessWidget {
|
|
final ReceiptItem item;
|
|
|
|
const ReceiptItemWidget({
|
|
super.key,
|
|
required this.item,
|
|
});
|
|
|
|
/// Memformat angka menjadi format mata uang Rupiah
|
|
String _formatRupiah(double amount) {
|
|
// Menggunakan NumberFormat untuk memformat angka
|
|
final formatter = NumberFormat("#,##0", "id_ID");
|
|
return "Rp ${formatter.format(amount)}";
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Mencoba menggunakan Google Fonts Courier Prime, jika gagal gunakan font sistem
|
|
TextStyle courierPrime;
|
|
try {
|
|
courierPrime = GoogleFonts.courierPrime(
|
|
textStyle: const TextStyle(
|
|
fontSize: 14,
|
|
height: 1.2,
|
|
),
|
|
);
|
|
} catch (e) {
|
|
// Fallback ke font sistem jika Google Fonts tidak tersedia
|
|
courierPrime = const TextStyle(
|
|
fontFamily: 'CourierPrime, Courier, monospace',
|
|
fontSize: 14,
|
|
height: 1.2,
|
|
);
|
|
}
|
|
|
|
return Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
|
|
color: Colors.white,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
// Nama item
|
|
Expanded(
|
|
flex: 4,
|
|
child: Text(
|
|
item.description,
|
|
style: courierPrime,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
// Quantity
|
|
Expanded(
|
|
flex: 1,
|
|
child: Text(
|
|
item.quantity.toString(),
|
|
textAlign: TextAlign.center,
|
|
style: courierPrime,
|
|
),
|
|
),
|
|
// Harga
|
|
Expanded(
|
|
flex: 2,
|
|
child: Text(
|
|
_formatRupiah(item.price),
|
|
textAlign: TextAlign.right,
|
|
style: courierPrime,
|
|
),
|
|
),
|
|
// Total
|
|
Expanded(
|
|
flex: 2,
|
|
child: Text(
|
|
_formatRupiah(item.total),
|
|
textAlign: TextAlign.right,
|
|
style: courierPrime,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
} |