175 lines
6.8 KiB
Dart
175 lines
6.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
import '../../l10n/app_localizations.dart';
|
|
import '../../models/closed_tab.dart';
|
|
import '../../models/closed_tab_item.dart';
|
|
import '../../models/payment_method.dart';
|
|
import '../../utils/easter_eggs.dart';
|
|
import '../../utils/money.dart';
|
|
import '../../utils/tab_orders.dart';
|
|
import 'order_history_list.dart';
|
|
|
|
class ClosedTabCard extends StatefulWidget {
|
|
final ClosedTab closedTab;
|
|
|
|
const ClosedTabCard({super.key, required this.closedTab});
|
|
|
|
@override
|
|
State<ClosedTabCard> createState() => _ClosedTabCardState();
|
|
}
|
|
|
|
class _ClosedTabCardState extends State<ClosedTabCard> {
|
|
bool _expanded = false;
|
|
|
|
IconData _paymentIcon(PaymentMethod method) {
|
|
return switch (method) {
|
|
PaymentMethod.payconiq => Icons.qr_code_rounded,
|
|
PaymentMethod.cash => Icons.money_rounded,
|
|
PaymentMethod.paymentPending => Icons.hourglass_empty,
|
|
};
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final closedTab = widget.closedTab;
|
|
final l10n = AppLocalizations.of(context);
|
|
final locale = Localizations.localeOf(context).toLanguageTag();
|
|
final dateFormat = DateFormat.yMMMd(locale).add_jm();
|
|
final scheme = Theme.of(context).colorScheme;
|
|
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: scheme.onSurface.withValues(alpha: 0.04),
|
|
borderRadius: BorderRadius.circular(14),
|
|
border: Border.all(color: scheme.onSurface.withValues(alpha: 0.06)),
|
|
),
|
|
clipBehavior: Clip.antiAlias,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
onTap: () => setState(() => _expanded = !_expanded),
|
|
enableFeedback: true,
|
|
splashFactory: NoSplash.splashFactory,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 14,
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
customerDisplayName(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(
|
|
switch (closedTab.paymentMethod) {
|
|
PaymentMethod.cash => l10n.cash,
|
|
PaymentMethod.payconiq => l10n.payconiq,
|
|
PaymentMethod.paymentPending =>
|
|
l10n.paymentPending,
|
|
},
|
|
style: TextStyle(
|
|
fontSize: 11,
|
|
fontWeight: FontWeight.w700,
|
|
color: scheme.primary,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
'${dateFormat.format(closedTab.closedAt)} · ${l10n.tabItemCount(closedTab.itemCount)}',
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
closedTab.totalInCents.asEuro,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w800,
|
|
color: scheme.onSurface,
|
|
),
|
|
),
|
|
const SizedBox(width: 4),
|
|
Icon(
|
|
_expanded
|
|
? Icons.expand_less_rounded
|
|
: Icons.expand_more_rounded,
|
|
color: scheme.onSurface.withValues(alpha: 0.5),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
AnimatedCrossFade(
|
|
duration: const Duration(milliseconds: 150),
|
|
crossFadeState: _expanded
|
|
? CrossFadeState.showFirst
|
|
: CrossFadeState.showSecond,
|
|
firstChild: Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 14),
|
|
child: Column(
|
|
children: [
|
|
const Divider(height: 1),
|
|
const SizedBox(height: 8),
|
|
OrderHistoryList(
|
|
orders: ordersOfClosedTab(closedTab),
|
|
productName: (ClosedTabItem item) => item.productName,
|
|
unitPriceInCents: (ClosedTabItem item) =>
|
|
item.unitPriceInCents,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
secondChild: const SizedBox(width: double.infinity),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|