fix: padding / history auto-reload
This commit is contained in:
@@ -71,8 +71,8 @@ class _BarScreenViewState extends State<BarScreenView> {
|
|||||||
},
|
},
|
||||||
icon: const Icon(Icons.logout),
|
icon: const Icon(Icons.logout),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
|
||||||
],
|
],
|
||||||
|
actionsPadding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
),
|
),
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
body: Builder(
|
body: Builder(
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:kooltab2/views/widgets/closed_tab_card.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../app/router.dart';
|
import '../app/router.dart';
|
||||||
@@ -21,7 +22,7 @@ class _HistoryScreenViewState extends State<HistoryScreenView> with RouteAware {
|
|||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
context.read<HistoryViewModel>().ensureLoaded();
|
context.read<HistoryViewModel>().load();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@ class _HistoryScreenViewState extends State<HistoryScreenView> with RouteAware {
|
|||||||
const Text('Tab History'),
|
const Text('Tab History'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
actionsPadding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: 'Refresh',
|
tooltip: 'Refresh',
|
||||||
@@ -122,7 +124,7 @@ class _HistoryScreenViewState extends State<HistoryScreenView> with RouteAware {
|
|||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final closedTab = viewModel.closedTabs[index];
|
final closedTab = viewModel.closedTabs[index];
|
||||||
|
|
||||||
return _ClosedTabCard(closedTab: closedTab);
|
return ClosedTabCard(closedTab: closedTab);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -170,157 +172,3 @@ class _EmptyState extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ClosedTabCard extends StatefulWidget {
|
|
||||||
final ClosedTab closedTab;
|
|
||||||
|
|
||||||
const _ClosedTabCard({required this.closedTab});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<_ClosedTabCard> createState() => _ClosedTabCardState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ClosedTabCardState extends State<_ClosedTabCard> {
|
|
||||||
bool _expanded = false;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final closedTab = widget.closedTab;
|
|
||||||
final dateFormat = DateFormat('MMM d, y · h:mm a');
|
|
||||||
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: Material(
|
|
||||||
color: Colors.transparent,
|
|
||||||
child: InkWell(
|
|
||||||
onTap: () => setState(() => _expanded = !_expanded),
|
|
||||||
enableFeedback: true,
|
|
||||||
splashFactory: NoSplash.splashFactory,
|
|
||||||
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 16,
|
|
||||||
vertical: 14,
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
closedTab.customerName,
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w800,
|
|
||||||
color: scheme.onSurface,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 2),
|
|
||||||
Text(
|
|
||||||
'${dateFormat.format(closedTab.closedAt)} · ${closedTab.itemCount} items',
|
|
||||||
style: Theme.of(context).textTheme.bodySmall,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
closedTab.formattedTotal,
|
|
||||||
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),
|
|
||||||
...closedTab.items.map(
|
|
||||||
(item) => _ClosedTabItemRow(item: item),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
secondChild: const SizedBox(width: double.infinity),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ClosedTabItemRow extends StatelessWidget {
|
|
||||||
final ClosedTabItem item;
|
|
||||||
|
|
||||||
const _ClosedTabItemRow({required this.item});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final unitPrice =
|
|
||||||
NumberFormat.simpleCurrency().format(item.unitPriceInCents / 100);
|
|
||||||
final lineTotal =
|
|
||||||
NumberFormat.simpleCurrency().format(item.lineTotalInCents / 100);
|
|
||||||
final scheme = Theme.of(context).colorScheme;
|
|
||||||
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
item.productName,
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: TextStyle(fontWeight: FontWeight.w600, color: scheme.onSurface),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
'${item.quantity} × $unitPrice',
|
|
||||||
style: Theme.of(context).textTheme.bodySmall,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
SizedBox(
|
|
||||||
width: 64,
|
|
||||||
child: Text(
|
|
||||||
lineTotal,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: TextStyle(fontWeight: FontWeight.w700, color: scheme.onSurface),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,7 +14,6 @@ class ProductListView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ProductListViewState extends State<ProductListView> {
|
class _ProductListViewState extends State<ProductListView> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -30,14 +29,16 @@ class _ProductListViewState extends State<ProductListView> {
|
|||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Products'),
|
title: Row(
|
||||||
actions: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: 'Back to bar',
|
onPressed: () => context.go('/bar'),
|
||||||
onPressed: () => context.go('/bar'),
|
icon: const Icon(Icons.arrow_back),
|
||||||
icon: const Icon(Icons.point_of_sale),
|
),
|
||||||
),
|
const SizedBox(width: 8),
|
||||||
],
|
const Text('Products'),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
floatingActionButton: FloatingActionButton.extended(
|
||||||
@@ -48,21 +49,15 @@ class _ProductListViewState extends State<ProductListView> {
|
|||||||
body: Builder(
|
body: Builder(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
if (viewModel.isLoading) {
|
if (viewModel.isLoading) {
|
||||||
return const Center(
|
return const Center(child: CircularProgressIndicator());
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewModel.errorMessage != null) {
|
if (viewModel.errorMessage != null) {
|
||||||
return Center(
|
return Center(child: Text(viewModel.errorMessage!));
|
||||||
child: Text(viewModel.errorMessage!),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewModel.products.isEmpty) {
|
if (viewModel.products.isEmpty) {
|
||||||
return const Center(
|
return const Center(child: Text('No products yet.'));
|
||||||
child: Text('No products yet.'),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ListView.separated(
|
return ListView.separated(
|
||||||
@@ -86,8 +81,7 @@ class _ProductListViewState extends State<ProductListView> {
|
|||||||
),
|
),
|
||||||
title: Text(product.name),
|
title: Text(product.name),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
'${product.category} • ${product
|
'${product.category} • ${product.formattedPrice} • Stock: ${product.stockQuantity}',
|
||||||
.formattedPrice} • Stock: ${product.stockQuantity}',
|
|
||||||
),
|
),
|
||||||
trailing: const Icon(Icons.chevron_right),
|
trailing: const Icon(Icons.chevron_right),
|
||||||
onTap: () => context.go('/products/${product.id}/edit'),
|
onTap: () => context.go('/products/${product.id}/edit'),
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
|||||||
child: const Text('Confirm'),
|
child: const Text('Confirm'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
actionsPadding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,158 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:kooltab2/models/closed_tab.dart';
|
||||||
|
import 'package:kooltab2/models/closed_tab_item.dart';
|
||||||
|
|
||||||
|
class ClosedTabCard extends StatefulWidget {
|
||||||
|
final ClosedTab closedTab;
|
||||||
|
|
||||||
|
const ClosedTabCard({required this.closedTab});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ClosedTabCard> createState() => _ClosedTabCardState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ClosedTabCardState extends State<ClosedTabCard> {
|
||||||
|
bool _expanded = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final closedTab = widget.closedTab;
|
||||||
|
final dateFormat = DateFormat('MMM d, y · h:mm a');
|
||||||
|
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: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () => setState(() => _expanded = !_expanded),
|
||||||
|
enableFeedback: true,
|
||||||
|
splashFactory: NoSplash.splashFactory,
|
||||||
|
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 16,
|
||||||
|
vertical: 14,
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
closedTab.customerName,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w800,
|
||||||
|
color: scheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 2),
|
||||||
|
Text(
|
||||||
|
'${dateFormat.format(closedTab.closedAt)} · ${closedTab.itemCount} items',
|
||||||
|
style: Theme.of(context).textTheme.bodySmall,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
closedTab.formattedTotal,
|
||||||
|
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),
|
||||||
|
...closedTab.items.map(
|
||||||
|
(item) => _ClosedTabItemRow(item: item),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
secondChild: const SizedBox(width: double.infinity),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ClosedTabItemRow extends StatelessWidget {
|
||||||
|
final ClosedTabItem item;
|
||||||
|
|
||||||
|
const _ClosedTabItemRow({required this.item});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final unitPrice =
|
||||||
|
NumberFormat.simpleCurrency().format(item.unitPriceInCents / 100);
|
||||||
|
final lineTotal =
|
||||||
|
NumberFormat.simpleCurrency().format(item.lineTotalInCents / 100);
|
||||||
|
final scheme = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
item.productName,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: TextStyle(fontWeight: FontWeight.w600, color: scheme.onSurface),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'${item.quantity} × $unitPrice',
|
||||||
|
style: Theme.of(context).textTheme.bodySmall,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
SizedBox(
|
||||||
|
width: 64,
|
||||||
|
child: Text(
|
||||||
|
lineTotal,
|
||||||
|
textAlign: TextAlign.end,
|
||||||
|
style: TextStyle(fontWeight: FontWeight.w700, color: scheme.onSurface),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user