Files
kooltab/lib/views/dialogs/close_tab_dialog.dart
T
2026-07-29 21:25:56 +02:00

121 lines
3.5 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';
import '../../viewmodels/bar_screen_view_model.dart';
import '../widgets/slide_confirm.dart';
Future<void> confirmCloseTab(BuildContext context) async {
final viewModel = context.read<BarScreenViewModel>();
final tab = viewModel.selectedTab;
if (tab == null) return;
String paymentMethod = 'cash';
final confirmed = await showDialog<bool>(
context: context,
builder: (dialogContext) {
return StatefulBuilder(
builder: (context, setDialogState) {
return AlertDialog(
title: Text('Close ${tab.customerName}ʼs tab?'),
content: SizedBox(
width: 360,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Current total: ${tab.formattedTotal}'),
const SizedBox(height: 20),
Text(
'Payment method',
style: Theme.of(context).textTheme.bodySmall,
),
const SizedBox(height: 8),
_PaymentPicker(
selected: paymentMethod,
onChanged: (value) {
setDialogState(() => paymentMethod = value);
},
),
const SizedBox(height: 24),
SlideConfirm(
onConfirmed: () {
Navigator.of(dialogContext).pop(true);
},
),
],
),
),
actionsPadding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text('Cancel'),
),
],
);
},
);
},
);
if (confirmed != true) return;
await viewModel.closeSelectedTab(paymentMethod: paymentMethod);
}
class _PaymentPicker extends StatelessWidget {
final String selected;
final ValueChanged<String> onChanged;
const _PaymentPicker({
required this.selected,
required this.onChanged,
});
static const _options = [
('cash', 'Cash'),
('payconiq', 'Payconiq'),
];
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: _options.map((option) {
final (value, label) = option;
final isSelected = selected == value;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 6),
child: ChoiceChip(
showCheckmark: false,
selected: isSelected,
onSelected: (_) => onChanged(value),
label: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (value == 'cash')
const Icon(
Icons.attach_money,
size: 16,
color: Colors.lightGreen,
)
else
SvgPicture.asset(
'assets/icons/payconic.svg',
width: 16,
height: 16,
colorFilter: ColorFilter.mode(Colors.pinkAccent, BlendMode.srcIn),
),
const SizedBox(width: 6),
Text(label),
],
),
),
);
}).toList(),
);
}
}