134 lines
4.1 KiB
Dart
134 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/svg.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
|
|
|
import '../../models/payment_method.dart';
|
|
import '../../viewmodels/bar_screen_view_model.dart';
|
|
import '../widgets/slide_confirm.dart';
|
|
import '../../l10n/app_localizations.dart';
|
|
|
|
Future<void> confirmCloseTab(BuildContext context) async {
|
|
final viewModel = context.read<BarScreenViewModel>();
|
|
final l10n = AppLocalizations.of(context);
|
|
final tab = viewModel.selectedTab;
|
|
|
|
if (tab == null) return;
|
|
|
|
PaymentMethod paymentMethod = PaymentMethod.cash;
|
|
|
|
final confirmed = await showDialog<bool>(
|
|
context: context,
|
|
builder: (dialogContext) {
|
|
return StatefulBuilder(
|
|
builder: (context, setDialogState) {
|
|
return AlertDialog(
|
|
title: Text(l10n.closeTabForCustomer(tab.customerName)),
|
|
content: SizedBox(
|
|
width: 360,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(l10n.currentTotal(tab.formattedTotal)),
|
|
const SizedBox(height: 20),
|
|
Text(
|
|
l10n.paymentMethod,
|
|
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: Text(l10n.cancel),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
|
|
if (confirmed != true) return;
|
|
|
|
try {
|
|
await viewModel.closeSelectedTab(paymentMethod: paymentMethod);
|
|
} catch (e, stack) {
|
|
Sentry.captureException(e, stackTrace: stack);
|
|
if (!context.mounted) return;
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text(l10n.couldNotCloseTab)));
|
|
}
|
|
}
|
|
|
|
class _PaymentPicker extends StatelessWidget {
|
|
final PaymentMethod selected;
|
|
final ValueChanged<PaymentMethod> onChanged;
|
|
|
|
const _PaymentPicker({required this.selected, required this.onChanged});
|
|
|
|
static const _options = [PaymentMethod.cash, PaymentMethod.payconiq];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context);
|
|
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: _options.map((option) {
|
|
final value = option;
|
|
final label = value == PaymentMethod.cash ? l10n.cash : l10n.payconiq;
|
|
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 == PaymentMethod.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(),
|
|
);
|
|
}
|
|
}
|