feat: add payment method

This commit is contained in:
2026-07-29 21:25:56 +02:00
parent cd75d3a474
commit 3cf4787e8c
14 changed files with 652 additions and 50 deletions
+101 -27
View File
@@ -1,7 +1,9 @@
import 'package:kooltab2/viewmodels/bar_screen_view_model.dart';
import 'package:kooltab2/views/widgets/slide_confirm.dart';
import 'package:provider/provider.dart';
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>();
@@ -9,39 +11,111 @@ Future<void> confirmCloseTab(BuildContext context) async {
if (tab == null) return;
String paymentMethod = 'cash';
final confirmed = await showDialog<bool>(
context: context,
builder: (dialogContext) {
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),
SlideConfirm(
onConfirmed: () {
Navigator.of(dialogContext).pop(true);
},
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'),
),
],
),
),
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();
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(),
);
}
}
+2
View File
@@ -219,6 +219,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
AppThemeMode.system => 'System',
AppThemeMode.light => 'Light',
AppThemeMode.dark => 'Dark',
AppThemeMode.ugly => 'Ugly',
},
onTap: () async {
final selected = await showModalBottomSheet<AppThemeMode>(
@@ -234,6 +235,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
AppThemeMode.system => 'System',
AppThemeMode.light => 'Light',
AppThemeMode.dark => 'Dark',
AppThemeMode.ugly => 'Ugly',
}),
onChanged: (value) =>
Navigator.pop(context, value),
+53 -10
View File
@@ -15,6 +15,13 @@ class ClosedTabCard extends StatefulWidget {
class _ClosedTabCardState extends State<ClosedTabCard> {
bool _expanded = false;
IconData _paymentIcon(String method) {
return switch (method) {
'payconiq' => Icons.qr_code_rounded,
_ => Icons.money_rounded,
};
}
@override
Widget build(BuildContext context) {
final closedTab = widget.closedTab;
@@ -49,15 +56,51 @@ class _ClosedTabCardState extends State<ClosedTabCard> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
closedTab.customerName,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w800,
color: scheme.onSurface,
),
Row(
children: [
Expanded(
child: Text(
closedTab.customerName,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w800,
color: scheme.onSurface,
),
),
),
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 3,
),
decoration: BoxDecoration(
color: scheme.primary.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(999),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
_paymentIcon(closedTab.paymentMethod),
size: 13,
color: scheme.primary,
),
const SizedBox(width: 4),
Text(
closedTab.formattedPaymentMethod,
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w700,
color: scheme.primary,
),
),
],
),
),
],
),
const SizedBox(height: 2),
Text(
@@ -163,4 +206,4 @@ class _ClosedTabItemRow extends StatelessWidget {
),
);
}
}
}