add cancel transaction
This commit is contained in:
@@ -304,6 +304,44 @@ class _TransaksiTabState extends State<_TransaksiTab> {
|
||||
|
||||
void _reload() => setState(() => _fut = widget.service.listTransaksi());
|
||||
|
||||
Future<void> _cancelTransaksi(Transaksi t) async {
|
||||
final confirm = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Batalkan Transaksi'),
|
||||
content: Text(
|
||||
'Apakah Anda yakin ingin membatalkan transaksi ${t.sahamTicker} (${t.volume} lembar)?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
child: const Text('Batal'),
|
||||
),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(backgroundColor: Colors.red),
|
||||
onPressed: () => Navigator.of(ctx).pop(true),
|
||||
child: const Text('Ya, Batalkan'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirm == true) {
|
||||
try {
|
||||
await widget.service.cancelTransaksi(t.id);
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Transaksi berhasil dibatalkan')),
|
||||
);
|
||||
_reload();
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Gagal membatalkan transaksi: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<List<Transaksi>>(
|
||||
@@ -327,15 +365,76 @@ class _TransaksiTabState extends State<_TransaksiTab> {
|
||||
itemBuilder: (c, i) {
|
||||
final t = list[i];
|
||||
final buy = t.isBuy;
|
||||
final isCancelled = t.isCancelled;
|
||||
return ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor:
|
||||
buy ? Colors.green : Colors.red,
|
||||
backgroundColor: isCancelled
|
||||
? Colors.grey
|
||||
: (buy ? Colors.green : Colors.red),
|
||||
child: Text(buy ? 'B' : 'J',
|
||||
style: const TextStyle(color: Colors.white))),
|
||||
title: Text('${t.sahamTicker} · ${t.volume} lbr'),
|
||||
subtitle: Text('${t.tanggal} @ ${_fmt(t.harga)} · fee ${_fmt(t.fee)}'),
|
||||
trailing: Text(_fmt(t.total)),
|
||||
title: Row(
|
||||
children: [
|
||||
Text(
|
||||
'${t.sahamTicker} · ${t.volume} lbr',
|
||||
style: TextStyle(
|
||||
decoration: isCancelled
|
||||
? TextDecoration.lineThrough
|
||||
: null,
|
||||
color: isCancelled ? Colors.grey : null,
|
||||
),
|
||||
),
|
||||
if (isCancelled) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red.shade100,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
'Dibatalkan',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Colors.red.shade900,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
subtitle: Text(
|
||||
'${t.tanggal} @ ${_fmt(t.harga)} · fee ${_fmt(t.fee)}',
|
||||
style: TextStyle(
|
||||
decoration: isCancelled
|
||||
? TextDecoration.lineThrough
|
||||
: null,
|
||||
color: isCancelled ? Colors.grey : null,
|
||||
),
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
_fmt(t.total),
|
||||
style: TextStyle(
|
||||
decoration: isCancelled
|
||||
? TextDecoration.lineThrough
|
||||
: null,
|
||||
color: isCancelled ? Colors.grey : null,
|
||||
),
|
||||
),
|
||||
if (!isCancelled)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.cancel_outlined,
|
||||
color: Colors.redAccent, size: 20),
|
||||
tooltip: 'Batalkan transaksi',
|
||||
onPressed: () => _cancelTransaksi(t),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user