167 lines
5.4 KiB
Dart
167 lines
5.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:cashumit/models/receipt_group.dart';
|
|
import 'package:cashumit/widgets/account_settings_widget.dart';
|
|
import 'package:cashumit/widgets/receipt_item_list.dart';
|
|
import 'package:cashumit/widgets/horizontal_divider.dart';
|
|
import 'package:cashumit/utils/currency_format.dart';
|
|
import 'package:cashumit/utils/app_text_styles.dart';
|
|
|
|
/// Section untuk satu grup transaksi (akun sumber + daftar item + subtotal).
|
|
class ReceiptGroupSection extends StatelessWidget {
|
|
final ReceiptGroup group;
|
|
final int groupIndex;
|
|
final VoidCallback onSelectSource;
|
|
final VoidCallback onRemoveGroup;
|
|
final Function(int)? onEditItem;
|
|
final Function(int)? onRemoveItem;
|
|
final VoidCallback onAddItem;
|
|
final VoidCallback? onEditTags;
|
|
final bool canRemove;
|
|
|
|
const ReceiptGroupSection({
|
|
super.key,
|
|
required this.group,
|
|
required this.groupIndex,
|
|
required this.onSelectSource,
|
|
required this.onRemoveGroup,
|
|
this.onEditItem,
|
|
this.onRemoveItem,
|
|
required this.onAddItem,
|
|
this.onEditTags,
|
|
this.canRemove = true,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final primaryColor = Theme.of(context).colorScheme.primary;
|
|
|
|
final card = Container(
|
|
margin: const EdgeInsets.only(bottom: 8),
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: Colors.grey[300]!),
|
|
borderRadius: BorderRadius.circular(4),
|
|
color: Colors.white,
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Header grup: dropdown "Dari:" + simbol tag + tombol hapus di kanan
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: SourceAccountSelector(
|
|
sourceAccount:
|
|
group.sourceAccountName ?? 'Pilih Sumber',
|
|
onSelectSource: onSelectSource,
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
// Simbol tag dengan counter badge
|
|
InkWell(
|
|
onTap: onEditTags,
|
|
borderRadius: BorderRadius.circular(20),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(4.0),
|
|
child: Badge(
|
|
label: Text(
|
|
'${group.tags.length}',
|
|
style: const TextStyle(
|
|
fontSize: 10,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
isLabelVisible: group.tags.isNotEmpty,
|
|
backgroundColor: primaryColor,
|
|
textColor: Colors.white,
|
|
child: Icon(
|
|
group.tags.isNotEmpty
|
|
? Icons.local_offer
|
|
: Icons.local_offer_outlined,
|
|
size: 22,
|
|
color: group.tags.isNotEmpty
|
|
? primaryColor
|
|
: Colors.grey[600],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
],
|
|
),
|
|
if (group.tags.isNotEmpty) ...[
|
|
const SizedBox(height: 6),
|
|
InkWell(
|
|
onTap: onEditTags,
|
|
borderRadius: BorderRadius.circular(4),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 2.0),
|
|
child: Wrap(
|
|
spacing: 8,
|
|
runSpacing: 4,
|
|
children: group.tags.map((tag) {
|
|
return Text(
|
|
'#$tag',
|
|
style: CourierStyles.base.copyWith(
|
|
fontSize: 11,
|
|
color: Colors.blueGrey[700],
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
const SizedBox(height: 8),
|
|
const HorizontalDivider(),
|
|
const SizedBox(height: 8),
|
|
// Daftar item grup
|
|
ReceiptItemList(
|
|
items: group.items,
|
|
onEditItem: onEditItem,
|
|
onRemoveItem: onRemoveItem,
|
|
onAddItem: onAddItem,
|
|
),
|
|
const SizedBox(height: 8),
|
|
// Subtotal grup
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
'Subtotal:',
|
|
style: CourierStyles.bold.copyWith(fontSize: 13),
|
|
),
|
|
Text(
|
|
CurrencyFormat.formatRupiah(group.total),
|
|
style: CourierStyles.bold
|
|
.copyWith(fontSize: 13, color: primaryColor),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
if (!canRemove) return card;
|
|
|
|
return Dismissible(
|
|
key: Key('group_${group.id}'),
|
|
direction: DismissDirection.endToStart,
|
|
background: Container(
|
|
margin: const EdgeInsets.only(bottom: 8),
|
|
alignment: Alignment.centerRight,
|
|
padding: const EdgeInsets.only(right: 16),
|
|
decoration: BoxDecoration(
|
|
color: Colors.red,
|
|
borderRadius: BorderRadius.circular(4),
|
|
),
|
|
child: const Icon(Icons.delete, color: Colors.white),
|
|
),
|
|
confirmDismiss: (_) async => true,
|
|
onDismissed: (_) => onRemoveGroup(),
|
|
child: card,
|
|
);
|
|
}
|
|
}
|