feat: add localisation

This commit is contained in:
2026-07-31 21:46:05 +02:00
parent b58c9a8722
commit f5b2041612
30 changed files with 4099 additions and 326 deletions
+48 -37
View File
@@ -14,6 +14,8 @@ import '../models/product.dart';
import '../models/tab_item.dart';
import '../utils/app_updater.dart';
import '../viewmodels/bar_screen_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
class BarScreenView extends StatefulWidget {
const BarScreenView({super.key});
@@ -33,40 +35,41 @@ class _BarScreenViewState extends State<BarScreenView> {
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
final viewModel = context.watch<BarScreenViewModel>();
final productsViewModel = context.watch<ProductListViewModel>();
return Scaffold(
appBar: AppBar(
title: const Text('Bar Tabs'),
title: Text(l10n.barTabs),
actions: [
IconButton(
tooltip: 'Manage products',
tooltip: l10n.manageProducts,
onPressed: () => context.go('/products'),
icon: const Icon(Icons.inventory_2_outlined),
),
const SizedBox(width: 6),
IconButton(
tooltip: 'Tab history',
tooltip: l10n.tabHistory,
onPressed: () => context.go('/history'),
icon: const Icon(Icons.history_rounded),
),
const SizedBox(width: 6),
IconButton(
tooltip: 'Refresh',
tooltip: l10n.refresh,
onPressed: () => viewModel.load(),
icon: const Icon(Icons.refresh_rounded),
),
const SizedBox(width: 6),
IconButton(
tooltip: 'Settings',
tooltip: l10n.settings,
onPressed: () => context.go('/settings'),
icon: const Icon(Icons.settings),
),
if (context.watch<PinLockViewModel>().isPinSet) ...[
const SizedBox(width: 6),
IconButton(
tooltip: 'Logout',
tooltip: l10n.logout,
onPressed: () {
Provider.of<PinLockViewModel>(context, listen: false).lock();
},
@@ -99,7 +102,7 @@ class _BarScreenViewState extends State<BarScreenView> {
),
const SizedBox(height: 12),
Text(
viewModel.errorMessage!,
l10n.localizedError(viewModel.errorMessage),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge,
),
@@ -119,9 +122,7 @@ class _BarScreenViewState extends State<BarScreenView> {
onProductTap: (product) async {
if (viewModel.selectedTab == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Open or select a tab first.'),
),
SnackBar(content: Text(l10n.openOrSelectTab)),
);
return;
}
@@ -131,9 +132,9 @@ class _BarScreenViewState extends State<BarScreenView> {
} catch (e, stack) {
Sentry.captureException(e, stackTrace: stack);
if (!context.mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('$e')));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(l10n.couldNotAddProductToTab)),
);
}
},
),
@@ -177,6 +178,7 @@ class _ProductGrid extends StatelessWidget {
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
if (products.isEmpty) {
return Center(
@@ -197,19 +199,19 @@ class _ProductGrid extends StatelessWidget {
),
const SizedBox(height: 16),
Text(
'No products yet',
l10n.noProductsYet,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 4),
Text(
'Add your first product to start selling.',
l10n.addFirstProduct,
style: Theme.of(context).textTheme.bodyMedium,
),
const SizedBox(height: 20),
FilledButton.icon(
onPressed: () => context.go('/products/new'),
icon: const Icon(Icons.add),
label: const Text('Add product'),
label: Text(l10n.addProduct),
),
],
),
@@ -223,7 +225,10 @@ class _ProductGrid extends StatelessWidget {
padding: const EdgeInsets.fromLTRB(20, 18, 20, 4),
child: Row(
children: [
Text('Products', style: Theme.of(context).textTheme.titleLarge),
Text(
l10n.products,
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(width: 10),
if (!hasSelectedTab)
Flexible(
@@ -247,7 +252,7 @@ class _ProductGrid extends StatelessWidget {
const SizedBox(width: 4),
Flexible(
child: Text(
'Select a tab to add items',
l10n.selectTabToAddItems,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodySmall,
),
@@ -335,6 +340,7 @@ class _TabPanelState extends State<_TabPanel> {
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
final filteredTabs = widget.tabs.where((tab) {
return tab.customerName.toLowerCase().contains(
@@ -362,8 +368,8 @@ class _TabPanelState extends State<_TabPanel> {
_searchQuery = value;
});
},
decoration: const InputDecoration(
hintText: 'Search by name…',
decoration: InputDecoration(
hintText: l10n.searchByName,
prefixIcon: Icon(Icons.search_rounded, size: 20),
isDense: true,
),
@@ -375,7 +381,7 @@ class _TabPanelState extends State<_TabPanel> {
IconButton.filled(
onPressed: widget.onNewTabPressed,
icon: const Icon(Icons.add_rounded),
tooltip: 'Open new tab',
tooltip: l10n.openNewTab,
),
],
),
@@ -385,7 +391,7 @@ class _TabPanelState extends State<_TabPanel> {
Row(
children: [
Text(
'OPEN TABS',
l10n.openTabs.toUpperCase(),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
fontWeight: FontWeight.w700,
letterSpacing: 0.8,
@@ -438,7 +444,7 @@ class _TabPanelState extends State<_TabPanel> {
),
const SizedBox(height: 10),
Text(
'Select or open a tab',
l10n.selectOrOpenTab,
style: Theme.of(context).textTheme.bodyMedium,
),
],
@@ -472,10 +478,11 @@ class _OpenTabsList extends StatelessWidget {
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
if (tabs.isEmpty) {
return Center(
child: Text(
'No open tabs',
l10n.noOpenTabs,
style: Theme.of(context).textTheme.bodyMedium,
),
);
@@ -501,7 +508,7 @@ class _OpenTabsList extends StatelessWidget {
SlidableAction(
onPressed: (_) => onTabSelected(tab.id),
icon: Icons.edit_outlined,
label: 'Edit',
label: l10n.edit,
backgroundColor: Theme.of(context).colorScheme.secondary,
foregroundColor: Theme.of(context).colorScheme.onSecondary,
),
@@ -513,13 +520,13 @@ class _OpenTabsList extends StatelessWidget {
Sentry.captureException(e, stackTrace: stack);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Could not close tab: $e')),
SnackBar(content: Text(l10n.couldNotCloseTab)),
);
}
}
},
icon: Icons.close_rounded,
label: 'Close',
label: l10n.close,
backgroundColor: Theme.of(context).colorScheme.error,
foregroundColor: Theme.of(context).colorScheme.onError,
),
@@ -567,7 +574,10 @@ class _OpenTabsList extends StatelessWidget {
),
const SizedBox(height: 4),
Text(
'${tab.itemCount} items - ${tab.formattedTotal}',
l10n.tabItemSummary(
tab.itemCount,
tab.formattedTotal,
),
style: Theme.of(context).textTheme.bodySmall,
),
],
@@ -598,6 +608,7 @@ class _SelectedTabDetails extends StatelessWidget {
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -629,7 +640,7 @@ class _SelectedTabDetails extends StatelessWidget {
),
const SizedBox(height: 8),
Text(
'Tap products to add them',
l10n.tapProductsToAdd,
style: Theme.of(context).textTheme.bodyMedium,
),
],
@@ -668,7 +679,10 @@ class _SelectedTabDetails extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Total', style: Theme.of(context).textTheme.bodySmall),
Text(
l10n.total,
style: Theme.of(context).textTheme.bodySmall,
),
Text(
tab.formattedTotal,
style: Theme.of(
@@ -680,7 +694,7 @@ class _SelectedTabDetails extends StatelessWidget {
),
FilledButton(
onPressed: tab.items.isEmpty ? null : onCloseTabPressed,
child: const Text('Close tab'),
child: Text(l10n.closeTab),
),
],
),
@@ -699,6 +713,7 @@ class _TabItemRow extends StatelessWidget {
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
@@ -739,9 +754,7 @@ class _TabItemRow extends StatelessWidget {
Sentry.captureException(e, stackTrace: stack);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Could not update quantity: $e'),
),
SnackBar(content: Text(l10n.couldNotUpdateQuantity)),
);
}
}
@@ -765,9 +778,7 @@ class _TabItemRow extends StatelessWidget {
Sentry.captureException(e, stackTrace: stack);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Could not update quantity: $e'),
),
SnackBar(content: Text(l10n.couldNotUpdateQuantity)),
);
}
}
+62 -55
View File
@@ -4,6 +4,8 @@ import 'package:provider/provider.dart';
import '../utils/app_update_util.dart';
import '../viewmodels/dev_menu_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
class DevMenuView extends StatefulWidget {
const DevMenuView({super.key});
@@ -35,10 +37,11 @@ class _DevMenuViewState extends State<DevMenuView> {
final message = vm.lastAction;
if (message == null) return;
final l10n = AppLocalizations.of(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message)),
);
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(l10n.devAction(message))));
}
@override
@@ -50,6 +53,7 @@ class _DevMenuViewState extends State<DevMenuView> {
@override
Widget build(BuildContext context) {
final vm = context.watch<DevMenuViewModel>();
final l10n = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(
@@ -57,109 +61,109 @@ class _DevMenuViewState extends State<DevMenuView> {
onPressed: () => context.pop(),
icon: const Icon(Icons.arrow_back),
),
title: const Text('Dev Menu'),
title: Text(l10n.devMenu),
centerTitle: true,
),
body: ListView(
padding: const EdgeInsets.symmetric(vertical: 12),
children: [
_Section(
title: 'Data Management',
title: l10n.dataManagement,
children: [
_Tile(
icon: Icons.delete_sweep_rounded,
title: 'Clear all open tabs',
title: l10n.clearOpenTabs,
onTap: vm.isLoading ? null : () => vm.clearOpenTabs(),
),
_Tile(
icon: Icons.history_rounded,
title: 'Clear closed tab history',
title: l10n.clearClosedHistory,
onTap: vm.isLoading ? null : () => vm.clearClosedTabHistory(),
),
_Tile(
icon: Icons.add_box_rounded,
title: 'Seed default products',
subtitle: 'Only seeds if table is empty',
title: l10n.seedDefaultProducts,
subtitle: l10n.onlySeedsWhenEmpty,
onTap: vm.isLoading ? null : () => vm.seedDefaultProducts(),
),
_Tile(
icon: Icons.restart_alt_rounded,
title: 'Clear & reseed products',
subtitle: 'Wipes all products, then seeds defaults',
title: l10n.clearAndReseedProducts,
subtitle: l10n.wipesAndReseeds,
onTap: vm.isLoading ? null : () => vm.clearAndReseedProducts(),
),
_Tile(
icon: Icons.delete_forever_rounded,
title: 'Clear all products',
title: l10n.clearAllProducts,
onTap: vm.isLoading ? null : () => vm.clearAllProducts(),
),
_Tile(
icon: Icons.image_rounded,
title: 'Clear product images',
subtitle: 'Deletes images from product_images folder',
title: l10n.clearProductImages,
subtitle: l10n.deletesProductImages,
onTap: vm.isLoading ? null : () => vm.clearProductImages(),
),
],
),
_Section(
title: 'Debugging',
title: l10n.debugging,
children: [
_Tile(
icon: Icons.lock_reset_rounded,
title: 'Reset PIN',
subtitle: 'Remove PIN lock',
title: l10n.resetPin,
subtitle: l10n.removePinLock,
onTap: vm.isLoading ? null : () => vm.resetPin(),
),
_Tile(
icon: Icons.bug_report_rounded,
title: 'Toggle debug overlay',
subtitle: 'Show FPS, memory, widget count',
title: l10n.toggleDebugOverlay,
subtitle: l10n.showFpsMemoryWidgets,
onTap: () => _showDebugOverlayInfo(),
),
_Tile(
icon: Icons.error_outline_rounded,
title: 'Error screen',
subtitle: 'View the error screen UI',
title: l10n.errorScreenMenu,
subtitle: l10n.viewErrorScreen,
onTap: () => context.push('/error'),
),
],
),
_Section(
title: 'Feature Toggles',
title: l10n.featureToggles,
children: [
_Tile(
icon: Icons.update_rounded,
title: 'Simulate update download',
subtitle: 'Open the download progress screen',
title: l10n.simulateUpdateDownload,
subtitle: l10n.openDownloadProgress,
onTap: () => _showSimulateUpdateDialog(),
),
],
),
_Section(
title: 'Testing Helpers',
title: l10n.testingHelpers,
children: [
_Tile(
icon: Icons.receipt_long_rounded,
title: 'Create test tab',
subtitle: 'Add tab with random items',
title: l10n.createTestTab,
subtitle: l10n.addRandomItems,
onTap: vm.isLoading ? null : () => vm.createTestTab(),
),
_Tile(
icon: Icons.grid_view_rounded,
title: 'Add 100 test products',
subtitle: 'Stress test product grid',
title: l10n.addTestProducts,
subtitle: l10n.stressTestGrid,
onTap: vm.isLoading ? null : () => vm.addTestProducts(),
),
_Tile(
icon: Icons.warning_rounded,
title: 'Simulate low stock',
subtitle: 'Set all products below threshold',
title: l10n.simulateLowStock,
subtitle: l10n.setProductsBelowThreshold,
onTap: vm.isLoading ? null : () => vm.simulateLowStock(),
),
_Tile(
icon: Icons.history_rounded,
title: 'Generate 100 mock orders',
subtitle: 'Random customers, items, and amounts',
title: l10n.generateMockOrders,
subtitle: l10n.randomCustomersItemsAmounts,
onTap: vm.isLoading
? null
: () => vm.generateMockOrders(count: 100),
@@ -167,16 +171,16 @@ class _DevMenuViewState extends State<DevMenuView> {
],
),
_Section(
title: 'Performance',
title: l10n.performance,
children: [
_Tile(
icon: Icons.image_rounded,
title: 'Clear image cache',
title: l10n.clearImageCache,
onTap: vm.isLoading ? null : () => vm.clearImageCache(),
),
_Tile(
icon: Icons.refresh_rounded,
title: 'Reload product images',
title: l10n.reloadProductImages,
onTap: vm.isLoading ? null : () => vm.reloadProductImages(),
),
],
@@ -192,18 +196,17 @@ class _DevMenuViewState extends State<DevMenuView> {
}
void _showDebugOverlayInfo() {
final l10n = AppLocalizations.of(context);
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Debug Overlay'),
content: const Text(
'The debug overlay shows FPS, memory usage, and widget counts. '
'Enable it via Flutter DevTools in debug mode.',
),
title: Text(l10n.debugOverlay),
content: Text(l10n.debugOverlayDescription),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
child: Text(l10n.ok),
),
],
),
@@ -211,10 +214,12 @@ class _DevMenuViewState extends State<DevMenuView> {
}
void _showSimulateUpdateDialog() {
final l10n = AppLocalizations.of(context);
final fakeUpdate = UpdateInfo(
update: true,
version: '99.0.0',
notes: 'Bug fixes and performance improvements.',
notes: l10n.simulatedUpdateNotes,
mandatory: false,
sha256: 'abc123',
download: 'https://example.com/fake-update.apk',
@@ -223,16 +228,16 @@ class _DevMenuViewState extends State<DevMenuView> {
showDialog(
context: context,
builder: (dialogContext) => AlertDialog(
title: const Text('Simulate update'),
title: Text(l10n.simulateUpdate),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Choose a simulation mode:'),
Text(l10n.chooseSimulationMode),
const SizedBox(height: 16),
_SimOption(
icon: Icons.download_rounded,
label: 'Successful download',
description: 'Progress 0→100%, then install, then done',
label: l10n.successfulDownload,
description: l10n.progressThenInstall,
onTap: () {
Navigator.pop(dialogContext);
context.push(
@@ -244,8 +249,8 @@ class _DevMenuViewState extends State<DevMenuView> {
const SizedBox(height: 8),
_SimOption(
icon: Icons.error_outline_rounded,
label: 'Download error',
description: 'Fails at 50% with a network timeout',
label: l10n.downloadError,
description: l10n.failsWithNetworkTimeout,
onTap: () {
Navigator.pop(dialogContext);
context.push(
@@ -257,8 +262,8 @@ class _DevMenuViewState extends State<DevMenuView> {
const SizedBox(height: 8),
_SimOption(
icon: Icons.wifi_off_rounded,
label: 'Real download (will fail)',
description: 'Attempts real OTA with fake URL',
label: l10n.realDownloadWillFail,
description: l10n.attemptsFakeUrl,
onTap: () {
Navigator.pop(dialogContext);
context.push('/update-progress', extra: fakeUpdate);
@@ -269,7 +274,7 @@ class _DevMenuViewState extends State<DevMenuView> {
actions: [
TextButton(
onPressed: () => Navigator.pop(dialogContext),
child: const Text('Cancel'),
child: Text(l10n.cancel),
),
],
),
@@ -312,7 +317,9 @@ class _SimOption extends StatelessWidget {
Text(
description,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.6),
color: Theme.of(
context,
).colorScheme.onSurface.withValues(alpha: 0.6),
),
),
],
@@ -415,8 +422,8 @@ class _Tile extends StatelessWidget {
Text(
subtitle!,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: scheme.onSurface.withValues(alpha: 0.5),
),
color: scheme.onSurface.withValues(alpha: 0.5),
),
),
],
),
+20 -18
View File
@@ -6,9 +6,11 @@ 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;
@@ -21,16 +23,16 @@ Future<void> confirmCloseTab(BuildContext context) async {
return StatefulBuilder(
builder: (context, setDialogState) {
return AlertDialog(
title: Text('Close ${tab.customerName}ʼs tab?'),
title: Text(l10n.closeTabForCustomer(tab.customerName)),
content: SizedBox(
width: 360,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Current total: ${tab.formattedTotal}'),
Text(l10n.currentTotal(tab.formattedTotal)),
const SizedBox(height: 20),
Text(
'Payment method',
l10n.paymentMethod,
style: Theme.of(context).textTheme.bodySmall,
),
const SizedBox(height: 8),
@@ -53,7 +55,7 @@ Future<void> confirmCloseTab(BuildContext context) async {
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text('Cancel'),
child: Text(l10n.cancel),
),
],
);
@@ -69,9 +71,9 @@ Future<void> confirmCloseTab(BuildContext context) async {
} catch (e, stack) {
Sentry.captureException(e, stackTrace: stack);
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Could not close tab: $e')),
);
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(l10n.couldNotCloseTab)));
}
}
@@ -79,22 +81,19 @@ class _PaymentPicker extends StatelessWidget {
final PaymentMethod selected;
final ValueChanged<PaymentMethod> onChanged;
const _PaymentPicker({
required this.selected,
required this.onChanged,
});
const _PaymentPicker({required this.selected, required this.onChanged});
static const _options = [
(PaymentMethod.cash, 'Cash'),
(PaymentMethod.payconiq, 'Payconiq'),
];
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, label) = option;
final value = option;
final label = value == PaymentMethod.cash ? l10n.cash : l10n.payconiq;
final isSelected = selected == value;
return Padding(
@@ -117,7 +116,10 @@ class _PaymentPicker extends StatelessWidget {
'assets/icons/payconic.svg',
width: 16,
height: 16,
colorFilter: ColorFilter.mode(Colors.pinkAccent, BlendMode.srcIn),
colorFilter: ColorFilter.mode(
Colors.pinkAccent,
BlendMode.srcIn,
),
),
const SizedBox(width: 6),
Text(label),
@@ -128,4 +130,4 @@ class _PaymentPicker extends StatelessWidget {
}).toList(),
);
}
}
}
+9 -7
View File
@@ -2,19 +2,21 @@ import 'package:flutter/material.dart';
import 'package:kooltab2/viewmodels/bar_screen_view_model.dart';
import 'package:provider/provider.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import '../../l10n/app_localizations.dart';
Future<void> showNewTabDialog(BuildContext context) async {
final l10n = AppLocalizations.of(context);
final controller = TextEditingController();
final name = await showDialog<String>(
context: context,
builder: (dialogContext) {
return AlertDialog(
title: const Text('Open new tab'),
title: Text(l10n.openNewTab),
content: TextField(
controller: controller,
autofocus: true,
decoration: const InputDecoration(labelText: 'Customer / group name'),
decoration: InputDecoration(labelText: l10n.customerGroupName),
onSubmitted: (value) {
Navigator.of(dialogContext).pop(value);
},
@@ -23,13 +25,13 @@ Future<void> showNewTabDialog(BuildContext context) async {
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(),
child: const Text('Cancel'),
child: Text(l10n.cancel),
),
FilledButton(
onPressed: () {
Navigator.of(dialogContext).pop(controller.text);
},
child: const Text('Open tab'),
child: Text(l10n.openTab),
),
],
);
@@ -45,8 +47,8 @@ Future<void> showNewTabDialog(BuildContext context) async {
} catch (e, stack) {
Sentry.captureException(e, stackTrace: stack);
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Could not create tab: $e')),
);
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(l10n.couldNotCreateTabMessage)));
}
}
+13 -10
View File
@@ -1,12 +1,15 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../l10n/app_localizations.dart';
class ErrorScreenView extends StatelessWidget {
const ErrorScreenView({super.key});
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(
@@ -14,7 +17,7 @@ class ErrorScreenView extends StatelessWidget {
onPressed: () => context.pop(),
icon: const Icon(Icons.arrow_back),
),
title: const Text('Error Screen'),
title: Text(l10n.errorScreen),
centerTitle: true,
),
body: Center(
@@ -37,24 +40,24 @@ class ErrorScreenView extends StatelessWidget {
),
const SizedBox(height: 24),
Text(
'Something went wrong',
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: scheme.error,
),
l10n.somethingWentWrong,
style: Theme.of(
context,
).textTheme.headlineMedium?.copyWith(color: scheme.error),
),
const SizedBox(height: 12),
Text(
'An unexpected error occurred.\nPlease try restarting the app.',
l10n.unexpectedError,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: scheme.onSurface.withValues(alpha: 0.6),
),
color: scheme.onSurface.withValues(alpha: 0.6),
),
),
const SizedBox(height: 32),
FilledButton.icon(
onPressed: () => context.go('/bar'),
icon: const Icon(Icons.home_rounded),
label: const Text('Go to bar screen'),
label: Text(l10n.goToBarScreen),
),
],
),
@@ -62,4 +65,4 @@ class ErrorScreenView extends StatelessWidget {
),
);
}
}
}
+23 -27
View File
@@ -5,6 +5,8 @@ import 'package:provider/provider.dart';
import '../app/router.dart';
import '../viewmodels/history_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
class HistoryScreenView extends StatefulWidget {
const HistoryScreenView({super.key});
@@ -55,6 +57,7 @@ class _HistoryScreenViewState extends State<HistoryScreenView> with RouteAware {
@override
Widget build(BuildContext context) {
final viewModel = context.watch<HistoryViewModel>();
final l10n = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(
@@ -65,13 +68,13 @@ class _HistoryScreenViewState extends State<HistoryScreenView> with RouteAware {
icon: const Icon(Icons.arrow_back),
),
const SizedBox(width: 5),
const Text('Tab History'),
Text(l10n.tabHistory),
],
),
actionsPadding: const EdgeInsets.symmetric(horizontal: 8),
actions: [
IconButton(
tooltip: 'Refresh',
tooltip: l10n.refresh,
onPressed: viewModel.load,
icon: const Icon(Icons.refresh_rounded),
),
@@ -100,7 +103,7 @@ class _HistoryScreenViewState extends State<HistoryScreenView> with RouteAware {
),
const SizedBox(height: 12),
Text(
viewModel.errorMessage!,
l10n.localizedError(viewModel.errorMessage),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge,
),
@@ -119,8 +122,8 @@ class _HistoryScreenViewState extends State<HistoryScreenView> with RouteAware {
Expanded(
child: TextField(
onChanged: viewModel.search,
decoration: const InputDecoration(
hintText: 'Search by name…',
decoration: InputDecoration(
hintText: l10n.searchByName,
prefixIcon: Icon(Icons.search_rounded, size: 20),
isDense: true,
),
@@ -141,12 +144,12 @@ class _HistoryScreenViewState extends State<HistoryScreenView> with RouteAware {
: ListView.separated(
controller: _scrollController,
padding: const EdgeInsets.fromLTRB(20, 8, 20, 20),
itemCount: viewModel.closedTabs.length +
itemCount:
viewModel.closedTabs.length +
(viewModel.hasMore || viewModel.isLoadingMore
? 1
: 0),
separatorBuilder: (_, _) =>
const SizedBox(height: 10),
separatorBuilder: (_, _) => const SizedBox(height: 10),
itemBuilder: (context, index) {
if (index == viewModel.closedTabs.length) {
return const Padding(
@@ -189,6 +192,7 @@ class _CustomerDropdown extends StatelessWidget {
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
final isFiltered = selectedCustomer != null;
return PopupMenuButton<String>(
@@ -204,17 +208,13 @@ class _CustomerDropdown extends StatelessWidget {
child: Row(
children: [
Icon(
isFiltered
? Icons.people_outline
: Icons.people_rounded,
isFiltered ? Icons.people_outline : Icons.people_rounded,
size: 18,
color: isFiltered
? null
: scheme.primary,
color: isFiltered ? null : scheme.primary,
),
const SizedBox(width: 10),
Text(
'All customers',
l10n.allCustomers,
style: TextStyle(
fontWeight: isFiltered ? FontWeight.w400 : FontWeight.w700,
color: isFiltered ? null : scheme.primary,
@@ -223,8 +223,7 @@ class _CustomerDropdown extends StatelessWidget {
],
),
),
if (customerNames.isNotEmpty)
const PopupMenuDivider(height: 1),
if (customerNames.isNotEmpty) const PopupMenuDivider(height: 1),
...customerNames.map(
(name) => PopupMenuItem<String>(
value: name,
@@ -237,9 +236,7 @@ class _CustomerDropdown extends StatelessWidget {
size: 18,
),
const SizedBox(width: 10),
Expanded(
child: Text(name, overflow: TextOverflow.ellipsis),
),
Expanded(child: Text(name, overflow: TextOverflow.ellipsis)),
],
),
),
@@ -250,9 +247,7 @@ class _CustomerDropdown extends StatelessWidget {
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(14),
border: Border.all(color: scheme.onSurface.withValues(alpha: 0.12)),
color: isFiltered
? scheme.primary.withValues(alpha: 0.08)
: null,
color: isFiltered ? scheme.primary.withValues(alpha: 0.08) : null,
),
child: Row(
mainAxisSize: MainAxisSize.min,
@@ -267,7 +262,7 @@ class _CustomerDropdown extends StatelessWidget {
const SizedBox(width: 6),
Flexible(
child: Text(
selectedCustomer ?? 'Customer',
selectedCustomer ?? l10n.customer,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.w600,
@@ -297,6 +292,7 @@ class _EmptyState extends StatelessWidget {
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
return Center(
child: Column(
@@ -316,16 +312,16 @@ class _EmptyState extends StatelessWidget {
),
const SizedBox(height: 16),
Text(
'No closed tabs yet',
l10n.noClosedTabs,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 4),
Text(
'Tabs you close will show up here.',
l10n.tabsYouCloseAppearHere,
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
);
}
}
}
+18 -13
View File
@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../viewmodels/pin_lock_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
enum PinEntryMode { unlock, create }
@@ -30,16 +32,14 @@ class _PinEntryViewState extends State<PinEntryView> {
bool get _isCreateFlow => widget.mode == PinEntryMode.create;
String get _title {
if (!_isCreateFlow) return 'Enter PIN';
return _isConfirmStep ? 'Confirm PIN' : 'Create a PIN';
String _title(AppLocalizations l10n) {
if (!_isCreateFlow) return l10n.enterPin;
return _isConfirmStep ? l10n.confirmPin : l10n.createPin;
}
String? get _subtitle {
String? _subtitle(AppLocalizations l10n) {
if (!_isCreateFlow) return null;
return _isConfirmStep
? 'Enter the same PIN again'
: 'Youʼll use this to unlock the app';
return _isConfirmStep ? l10n.confirmPinSubtitle : l10n.enterPinSubtitle;
}
void _onDigitPressed(String digit) {
@@ -65,6 +65,7 @@ class _PinEntryViewState extends State<PinEntryView> {
Future<void> _handleComplete() async {
final viewModel = context.read<PinLockViewModel>();
final l10n = AppLocalizations.of(context);
if (_isCreateFlow && !_isConfirmStep) {
// First entry of a new PIN — stash it, then ask for confirmation.
@@ -84,7 +85,7 @@ class _PinEntryViewState extends State<PinEntryView> {
_firstEntry = null;
_isConfirmStep = false;
});
_fail('PINs didnʼt match. Try again.');
_fail(l10n.pinsDidNotMatch);
return;
}
@@ -100,7 +101,7 @@ class _PinEntryViewState extends State<PinEntryView> {
_firstEntry = null;
_isConfirmStep = false;
});
_fail(viewModel.errorMessage ?? 'Something went wrong.');
_fail(l10n.localizedError(viewModel.errorMessage));
}
return;
}
@@ -114,7 +115,7 @@ class _PinEntryViewState extends State<PinEntryView> {
if (ok) {
widget.onSuccess?.call();
} else {
_fail(viewModel.errorMessage ?? 'Incorrect PIN.');
_fail(l10n.localizedError(viewModel.errorMessage));
}
}
@@ -133,6 +134,7 @@ class _PinEntryViewState extends State<PinEntryView> {
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
return Scaffold(
body: SafeArea(
@@ -143,11 +145,14 @@ class _PinEntryViewState extends State<PinEntryView> {
const Spacer(flex: 2),
Icon(Icons.lock_outline_rounded, size: 36, color: scheme.primary),
const SizedBox(height: 16),
Text(_title, style: Theme.of(context).textTheme.headlineMedium),
if (_subtitle != null) ...[
Text(
_title(l10n),
style: Theme.of(context).textTheme.headlineMedium,
),
if (_subtitle(l10n) != null) ...[
const SizedBox(height: 6),
Text(
_subtitle!,
_subtitle(l10n)!,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium,
),
+48 -43
View File
@@ -10,6 +10,8 @@ import 'package:sentry_flutter/sentry_flutter.dart';
import '../models/product.dart';
import '../viewmodels/product_list_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
class ProductFormView extends StatefulWidget {
final String? productId;
@@ -48,6 +50,7 @@ class _ProductFormViewState extends State<ProductFormView> {
}
Future<void> _loadProductIfNeeded() async {
final l10n = AppLocalizations.of(context);
if (!widget.isEditing) {
setState(() => _isLoading = false);
return;
@@ -62,7 +65,7 @@ class _ProductFormViewState extends State<ProductFormView> {
if (product == null) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Product not found.')));
).showSnackBar(SnackBar(content: Text(l10n.productNotFound)));
context.go('/products');
return;
@@ -83,7 +86,7 @@ class _ProductFormViewState extends State<ProductFormView> {
if (!mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Could not load product: $e')));
).showSnackBar(SnackBar(content: Text(l10n.couldNotLoadProduct)));
context.go('/products');
}
}
@@ -120,11 +123,11 @@ class _ProductFormViewState extends State<ProductFormView> {
Future<void> _pickImage() async {
final pickedFile = await _imagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 80,
maxWidth: 1000,
maxHeight: 1000,
);
source: ImageSource.gallery,
imageQuality: 80,
maxWidth: 1000,
maxHeight: 1000,
);
if (pickedFile == null) return;
@@ -146,19 +149,20 @@ class _ProductFormViewState extends State<ProductFormView> {
}
Future<void> _save() async {
final l10n = AppLocalizations.of(context);
if (!_formKey.currentState!.validate()) return;
if (_imagePath == null || _imagePath!.isEmpty) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Choose a product image.')));
).showSnackBar(SnackBar(content: Text(l10n.chooseImage)));
return;
}
if (_selectedCategory == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Please select a category.')),
);
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(l10n.selectCategory)));
return;
}
@@ -198,9 +202,9 @@ class _ProductFormViewState extends State<ProductFormView> {
Sentry.captureException(e, stackTrace: stack);
if (!mounted) return;
setState(() => _isSaving = false);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Could not save product: $e')),
);
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(l10n.couldNotSaveProduct)));
return;
}
@@ -212,23 +216,22 @@ class _ProductFormViewState extends State<ProductFormView> {
Future<void> _delete() async {
if (!widget.isEditing) return;
final l10n = AppLocalizations.of(context);
final confirmed = await showDialog<bool>(
context: context,
builder: (dialogContext) {
return AlertDialog(
title: const Text('Delete product?'),
content: const Text(
'This will remove the product from the product list.',
),
title: Text(l10n.deleteProduct),
content: Text(l10n.deleteProductDescription),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text('Cancel'),
child: Text(l10n.cancel),
),
FilledButton(
onPressed: () => Navigator.of(dialogContext).pop(true),
child: const Text('Delete'),
child: Text(l10n.delete),
),
],
);
@@ -244,9 +247,9 @@ class _ProductFormViewState extends State<ProductFormView> {
} catch (e, stack) {
Sentry.captureException(e, stackTrace: stack);
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Could not delete product: $e')),
);
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(l10n.couldNotDeleteProduct)));
return;
}
@@ -256,6 +259,7 @@ class _ProductFormViewState extends State<ProductFormView> {
}
Widget _buildImagePicker(BuildContext context) {
final l10n = AppLocalizations.of(context);
return InkWell(
onTap: _pickImage,
@@ -289,7 +293,7 @@ class _ProductFormViewState extends State<ProductFormView> {
child: FilledButton.icon(
onPressed: _pickImage,
icon: const Icon(Icons.image),
label: const Text('Change image'),
label: Text(l10n.changeImage),
),
),
],
@@ -301,7 +305,7 @@ class _ProductFormViewState extends State<ProductFormView> {
const Icon(Icons.add_photo_alternate_outlined, size: 48),
const SizedBox(height: 12),
Text(
'Choose product image',
l10n.chooseProductImage,
style: Theme.of(context).textTheme.titleMedium,
),
],
@@ -313,7 +317,8 @@ class _ProductFormViewState extends State<ProductFormView> {
@override
Widget build(BuildContext context) {
final title = widget.isEditing ? 'Edit product' : 'Add product';
final l10n = AppLocalizations.of(context);
final title = widget.isEditing ? l10n.editProduct : l10n.addProduct;
return Scaffold(
appBar: AppBar(
@@ -345,14 +350,14 @@ class _ProductFormViewState extends State<ProductFormView> {
const SizedBox(height: 24),
TextFormField(
controller: _nameController,
decoration: const InputDecoration(
labelText: 'Product name',
decoration: InputDecoration(
labelText: l10n.productName,
border: OutlineInputBorder(),
),
textInputAction: TextInputAction.next,
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Enter a product name.';
return l10n.enterProductName;
}
return null;
@@ -370,13 +375,13 @@ class _ProductFormViewState extends State<ProductFormView> {
enableSearch: true,
controller: _categoryController,
requestFocusOnTap: true,
label: const Text('Category'),
hintText: 'Select a category',
label: Text(l10n.category),
hintText: l10n.selectCategory,
dropdownMenuEntries: viewModel.categories
.map(
(category) => DropdownMenuEntry<String>(
value: category,
label: category,
label: l10n.categoryLabel(category),
),
)
.toList(),
@@ -393,8 +398,8 @@ class _ProductFormViewState extends State<ProductFormView> {
const SizedBox(height: 16),
TextFormField(
controller: _priceController,
decoration: const InputDecoration(
labelText: 'Price',
decoration: InputDecoration(
labelText: l10n.price,
prefixText: '',
border: OutlineInputBorder(),
),
@@ -404,14 +409,14 @@ class _ProductFormViewState extends State<ProductFormView> {
textInputAction: TextInputAction.next,
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Enter a price.';
return l10n.enterPrice;
}
final normalized = value.replaceAll(',', '.');
final price = double.tryParse(normalized);
if (price == null || price < 0) {
return 'Enter a valid price.';
return l10n.enterValidPrice;
}
return null;
@@ -420,8 +425,8 @@ class _ProductFormViewState extends State<ProductFormView> {
const SizedBox(height: 16),
TextFormField(
controller: _stockController,
decoration: const InputDecoration(
labelText: 'Current stock',
decoration: InputDecoration(
labelText: l10n.stock,
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
@@ -430,7 +435,7 @@ class _ProductFormViewState extends State<ProductFormView> {
final number = int.tryParse(value ?? '');
if (number == null || number < 0) {
return 'Enter a valid stock amount.';
return l10n.enterValidStock;
}
return null;
@@ -439,8 +444,8 @@ class _ProductFormViewState extends State<ProductFormView> {
const SizedBox(height: 16),
TextFormField(
controller: _lowStockController,
decoration: const InputDecoration(
labelText: 'Low stock warning threshold',
decoration: InputDecoration(
labelText: l10n.lowStockThreshold,
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
@@ -448,7 +453,7 @@ class _ProductFormViewState extends State<ProductFormView> {
final number = int.tryParse(value ?? '');
if (number == null || number < 0) {
return 'Enter a valid threshold.';
return l10n.enterValidThreshold;
}
return null;
@@ -467,7 +472,7 @@ class _ProductFormViewState extends State<ProductFormView> {
)
: const Icon(Icons.save),
label: Text(
widget.isEditing ? 'Save changes' : 'Add product',
widget.isEditing ? l10n.confirm : l10n.addProduct,
),
),
],
+20 -9
View File
@@ -5,6 +5,8 @@ import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import '../viewmodels/product_list_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
class ProductListView extends StatefulWidget {
const ProductListView({super.key});
@@ -26,6 +28,7 @@ class _ProductListViewState extends State<ProductListView> {
@override
Widget build(BuildContext context) {
final viewModel = context.watch<ProductListViewModel>();
final l10n = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(
@@ -36,7 +39,7 @@ class _ProductListViewState extends State<ProductListView> {
icon: const Icon(Icons.arrow_back),
),
const SizedBox(width: 8),
const Text('Products'),
Text(l10n.products),
],
),
),
@@ -44,7 +47,7 @@ class _ProductListViewState extends State<ProductListView> {
floatingActionButton: FloatingActionButton.extended(
onPressed: () => context.go('/products/new'),
icon: const Icon(Icons.add),
label: const Text('Add product'),
label: Text(l10n.addProduct),
),
body: Builder(
builder: (context) {
@@ -53,11 +56,13 @@ class _ProductListViewState extends State<ProductListView> {
}
if (viewModel.errorMessage != null) {
return Center(child: Text(viewModel.errorMessage!));
return Center(
child: Text(l10n.localizedError(viewModel.errorMessage)),
);
}
if (viewModel.products.isEmpty) {
return const Center(child: Text('No products yet.'));
return Center(child: Text(l10n.noProductsYet));
}
return ListView.separated(
@@ -73,22 +78,28 @@ class _ProductListViewState extends State<ProductListView> {
width: 56,
height: 56,
child: Center(
child: product.imagePath != null &&
child:
product.imagePath != null &&
product.imagePath!.isNotEmpty
? Image.file(
File(product.imagePath!),
fit: BoxFit.contain,
cacheWidth: 112,
errorBuilder:
(context, error, stackTrace) =>
const Icon(Icons.image_not_supported_outlined),
errorBuilder: (context, error, stackTrace) =>
const Icon(
Icons.image_not_supported_outlined,
),
)
: const Icon(Icons.image_not_supported_outlined),
),
),
title: Text(product.name),
subtitle: Text(
'${product.category}${product.formattedPrice} • Stock: ${product.stockQuantity}',
l10n.productStockSummary(
l10n.categoryLabel(product.category),
product.formattedPrice,
product.stockQuantity,
),
),
trailing: const Icon(Icons.chevron_right),
onTap: () => context.go('/products/${product.id}/edit'),
+86 -42
View File
@@ -10,6 +10,8 @@ import '../models/settings.dart';
import '../utils/app_update_util.dart';
import '../viewmodels/pin_lock_view_model.dart';
import '../viewmodels/settings_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
class SettingsScreenView extends StatefulWidget {
const SettingsScreenView({super.key});
@@ -58,8 +60,9 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
});
}
Future<String?> _promptPin(String title, {String hint = 'Enter PIN (4 digits)'}) {
Future<String?> _promptPin(String title, {String? hint}) {
final controller = TextEditingController();
final l10n = AppLocalizations.of(context);
return showDialog<String>(
context: context,
@@ -81,12 +84,12 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
child: Text(l10n.cancel),
),
const SizedBox(width: 12),
FilledButton(
onPressed: () => Navigator.pop(context, controller.text),
child: const Text('Confirm'),
child: Text(l10n.confirm),
),
],
),
@@ -101,11 +104,12 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
}
Future<void> _enablePin() async {
final pin = await _promptPin('Set PIN Code', hint: '4 digits');
final l10n = AppLocalizations.of(context);
final pin = await _promptPin(l10n.setPinCode, hint: l10n.fourDigits);
if (pin == null) return;
if (pin.length != 4) {
_showError('PIN must be exactly 4 digits');
_showError(l10n.pinExactlyFour);
return;
}
@@ -113,7 +117,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
final success = await pinLockViewModel.setPin(pin);
if (!success) {
_showError(pinLockViewModel.errorMessage ?? 'Could not set PIN.');
_showError(l10n.localizedError(pinLockViewModel.errorMessage));
return;
}
@@ -123,19 +127,20 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
await context.read<SettingsViewModel>().updatePinRequired(true);
} catch (e, stack) {
Sentry.captureException(e, stackTrace: stack);
_showError('Could not save PIN setting.');
_showError(l10n.couldNotSavePin);
}
}
Future<void> _changePin() async {
final current = await _promptPin('Enter Current PIN');
final l10n = AppLocalizations.of(context);
final current = await _promptPin(l10n.enterCurrentPin);
if (current == null) return;
final newPin = await _promptPin('Enter New PIN', hint: '4 digits');
final newPin = await _promptPin(l10n.enterNewPin, hint: l10n.fourDigits);
if (newPin == null) return;
if (newPin.length != 4) {
_showError('PIN must be exactly 4 digits');
_showError(l10n.pinExactlyFour);
return;
}
@@ -146,19 +151,20 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
);
if (!success) {
_showError(pinLockViewModel.errorMessage ?? 'Could not change PIN.');
_showError(l10n.localizedError(pinLockViewModel.errorMessage));
}
}
Future<void> _disablePin() async {
final current = await _promptPin('Enter Current PIN to Disable');
final l10n = AppLocalizations.of(context);
final current = await _promptPin(l10n.enterCurrentPin);
if (current == null) return;
final pinLockViewModel = context.read<PinLockViewModel>();
final success = await pinLockViewModel.disablePin(current);
if (!success) {
_showError(pinLockViewModel.errorMessage ?? 'Could not disable PIN.');
_showError(l10n.localizedError(pinLockViewModel.errorMessage));
return;
}
@@ -168,12 +174,13 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
await context.read<SettingsViewModel>().updatePinRequired(false);
} catch (e, stack) {
Sentry.captureException(e, stackTrace: stack);
_showError('Could not save PIN setting.');
_showError(l10n.couldNotSavePin);
}
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
final settingsViewModel = context.watch<SettingsViewModel>();
final pinLockViewModel = context.watch<PinLockViewModel>();
@@ -186,7 +193,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
icon: const Icon(Icons.arrow_back),
),
const SizedBox(width: 5),
const Text('Settings'),
Text(l10n.settingsTitle),
],
),
),
@@ -209,11 +216,11 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
padding: const EdgeInsets.symmetric(vertical: 12),
children: [
_SettingsSection(
title: 'Security',
title: l10n.security,
children: [
_SettingsSwitchTile(
icon: Icons.lock_outline_rounded,
title: 'PIN Required',
title: l10n.pinRequired,
value: settings.pinRequired,
onChanged: (value) {
if (value) {
@@ -226,22 +233,58 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
if (settings.pinRequired)
_SettingsTile(
icon: Icons.pin_rounded,
title: 'Change PIN',
title: l10n.changePin,
onTap: _changePin,
),
],
),
_SettingsSection(
title: 'Appearance',
title: l10n.appearance,
children: [
_SettingsTile(
icon: Icons.language_rounded,
title: l10n.language,
subtitle: switch (settings.language) {
AppLanguage.system => l10n.languageSystem,
AppLanguage.english => l10n.languageEnglish,
AppLanguage.dutch => l10n.languageDutch,
},
onTap: () async {
final selected = await showModalBottomSheet<AppLanguage>(
context: context,
builder: (context) => SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: AppLanguage.values.map((language) {
return RadioListTile<AppLanguage>(
value: language,
groupValue: settings.language,
title: Text(switch (language) {
AppLanguage.system => l10n.languageSystem,
AppLanguage.english => l10n.languageEnglish,
AppLanguage.dutch => l10n.languageDutch,
}),
onChanged: (value) =>
Navigator.pop(context, value),
);
}).toList(),
),
),
);
if (selected != null) {
await settingsViewModel.updateLanguage(selected);
}
},
),
_SettingsTile(
icon: Icons.brightness_6_rounded,
title: 'Theme',
title: l10n.theme,
subtitle: switch (settings.themeMode) {
AppThemeMode.system => 'System',
AppThemeMode.light => 'Light',
AppThemeMode.dark => 'Dark',
AppThemeMode.ugly => 'Ugly',
AppThemeMode.system => l10n.system,
AppThemeMode.light => l10n.light,
AppThemeMode.dark => l10n.dark,
AppThemeMode.ugly => l10n.ugly,
},
onTap: () async {
final selected = await showModalBottomSheet<AppThemeMode>(
@@ -254,10 +297,10 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
value: mode,
groupValue: settings.themeMode,
title: Text(switch (mode) {
AppThemeMode.system => 'System',
AppThemeMode.light => 'Light',
AppThemeMode.dark => 'Dark',
AppThemeMode.ugly => 'Ugly',
AppThemeMode.system => l10n.system,
AppThemeMode.light => l10n.light,
AppThemeMode.dark => l10n.dark,
AppThemeMode.ugly => l10n.ugly,
}),
onChanged: (value) =>
Navigator.pop(context, value),
@@ -276,13 +319,13 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
),
if (Platform.isAndroid)
_SettingsSection(
title: 'Updates',
title: l10n.updates,
children: [
_SettingsTile(
icon: Icons.system_update_alt_rounded,
title: settingsViewModel.checkingForUpdates
? 'Checking for updates...'
: 'Check for updates',
? l10n.checkingForUpdates
: l10n.checkForUpdates,
onTap: settingsViewModel.checkingForUpdates
? null
: _checkForUpdates,
@@ -294,7 +337,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
onTap: _onVersionTap,
child: Center(
child: Text(
'Version $_appVersion',
l10n.version(_appVersion),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(
context,
@@ -313,6 +356,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
Future<void> _checkForUpdates() async {
if (!Platform.isAndroid) return;
final l10n = AppLocalizations.of(context);
final vm = context.read<SettingsViewModel>();
try {
@@ -321,11 +365,9 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
if (!mounted) return;
if (update == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('You are already on the latest version.'),
),
);
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(l10n.latestVersion)));
return;
}
@@ -336,21 +378,23 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Update check failed: $e')));
).showSnackBar(SnackBar(content: Text(l10n.updateCheckFailed)));
}
}
void _showUpdateDialog(UpdateInfo update) {
final l10n = AppLocalizations.of(context);
showDialog(
context: context,
barrierDismissible: !update.mandatory,
builder: (dialogContext) => AlertDialog(
title: const Text("Update available"),
title: Text(l10n.updateAvailable),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Version ${update.version} is available."),
Text(l10n.versionAvailable(update.version)),
const SizedBox(height: 12),
Text(update.notes),
],
@@ -359,14 +403,14 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
if (!update.mandatory)
TextButton(
onPressed: () => Navigator.pop(dialogContext),
child: const Text("Later"),
child: Text(l10n.later),
),
FilledButton(
onPressed: () {
Navigator.pop(dialogContext);
context.push('/update-progress', extra: update);
},
child: const Text("Update"),
child: Text(l10n.update),
),
],
),
+35 -26
View File
@@ -3,6 +3,8 @@ import 'package:go_router/go_router.dart';
import '../utils/app_update_util.dart';
import '../viewmodels/update_progress_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
class UpdateProgressView extends StatefulWidget {
final UpdateInfo update;
@@ -46,28 +48,27 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
}
void _showRestartDialog() {
final l10n = AppLocalizations.of(context);
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: const Text('Update ready'),
content: const Text(
'The update has been downloaded and installed. '
'Restart the app now to apply the changes.',
),
title: Text(l10n.updateReady),
content: Text(l10n.updateReadyDescription),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
this.context.go('/bar');
},
child: const Text('Later'),
child: Text(l10n.later),
),
FilledButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Restart app'),
child: Text(l10n.restartApp),
),
],
),
@@ -75,12 +76,14 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
}
void _showErrorSnackBar() {
final l10n = AppLocalizations.of(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(_vm.errorMessage ?? 'Update failed'),
content: Text(l10n.updateError(_vm.errorMessage)),
backgroundColor: Theme.of(context).colorScheme.error,
action: SnackBarAction(
label: 'Retry',
label: l10n.retry,
onPressed: () {
_vm.cancel();
_vm.start();
@@ -99,13 +102,15 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.close),
onPressed: () => _showCancelDialog(),
),
title: const Text('Updating'),
title: Text(l10n.updating),
centerTitle: true,
automaticallyImplyLeading: false,
),
@@ -138,6 +143,8 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
}
Widget _buildHeader() {
final l10n = AppLocalizations.of(context);
return Column(
children: [
Container(
@@ -153,13 +160,10 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
),
),
const SizedBox(height: 24),
Text(
'KoolTab',
style: Theme.of(context).textTheme.headlineMedium,
),
Text('KoolTab', style: Theme.of(context).textTheme.headlineMedium),
const SizedBox(height: 8),
Text(
'Version ${widget.update.version}',
l10n.version(widget.update.version),
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.primary,
),
@@ -170,6 +174,7 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
Widget _buildProgress(UpdateProgressViewModel vm) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
return Column(
children: [
@@ -211,7 +216,7 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
),
const SizedBox(height: 4),
Text(
vm.phase == OtaPhase.installing ? 'Installing' : '',
vm.phase == OtaPhase.installing ? l10n.installing : '',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: scheme.onSurface.withValues(alpha: 0.6),
),
@@ -234,6 +239,7 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
Widget _buildStatus(UpdateProgressViewModel vm) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
final color = switch (vm.phase) {
OtaPhase.error => scheme.error,
@@ -242,13 +248,15 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
};
return Text(
vm.statusText,
l10n.updateStatus(vm.statusText),
style: Theme.of(context).textTheme.titleMedium?.copyWith(color: color),
textAlign: TextAlign.center,
);
}
Widget _buildVersionInfo(UpdateProgressViewModel vm) {
final l10n = AppLocalizations.of(context);
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
@@ -259,9 +267,11 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
),
const SizedBox(width: 6),
Text(
'Do not close the app during the update',
l10n.doNotCloseDuringUpdate,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.4),
color: Theme.of(
context,
).colorScheme.onSurface.withValues(alpha: 0.4),
),
),
],
@@ -269,18 +279,17 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
}
void _showCancelDialog() {
final l10n = AppLocalizations.of(context);
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Cancel update?'),
content: const Text(
'The update is in progress. If you leave now, '
'the app may become unstable.',
),
title: Text(l10n.cancelUpdate),
content: Text(l10n.cancelUpdateDescription),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Continue update'),
child: Text(l10n.continueUpdate),
),
FilledButton(
style: FilledButton.styleFrom(
@@ -291,7 +300,7 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
_vm.cancel();
this.context.go('/bar');
},
child: const Text('Cancel update'),
child: Text(l10n.cancelUpdateAction),
),
],
),
+18 -10
View File
@@ -4,6 +4,8 @@ import 'package:kooltab2/models/closed_tab.dart';
import 'package:kooltab2/models/closed_tab_item.dart';
import 'package:kooltab2/models/payment_method.dart';
import '../../l10n/app_localizations.dart';
class ClosedTabCard extends StatefulWidget {
final ClosedTab closedTab;
@@ -26,7 +28,9 @@ class _ClosedTabCardState extends State<ClosedTabCard> {
@override
Widget build(BuildContext context) {
final closedTab = widget.closedTab;
final dateFormat = DateFormat('MMM d, y · h:mm a');
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(
@@ -91,7 +95,10 @@ class _ClosedTabCardState extends State<ClosedTabCard> {
),
const SizedBox(width: 4),
Text(
closedTab.formattedPaymentMethod,
switch (closedTab.paymentMethod) {
PaymentMethod.cash => l10n.cash,
PaymentMethod.payconiq => l10n.payconiq,
},
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w700,
@@ -105,7 +112,7 @@ class _ClosedTabCardState extends State<ClosedTabCard> {
),
const SizedBox(height: 2),
Text(
'${dateFormat.format(closedTab.closedAt)} · ${closedTab.itemCount} items',
'${dateFormat.format(closedTab.closedAt)} · ${l10n.tabItemCount(closedTab.itemCount)}',
style: Theme.of(context).textTheme.bodySmall,
),
],
@@ -164,12 +171,13 @@ class _ClosedTabItemRow extends StatelessWidget {
@override
Widget build(BuildContext context) {
final unitPrice = NumberFormat.simpleCurrency().format(
item.unitPriceInCents / 100,
);
final lineTotal = NumberFormat.simpleCurrency().format(
item.lineTotalInCents / 100,
);
final locale = Localizations.localeOf(context).toLanguageTag();
final unitPrice = NumberFormat.simpleCurrency(
locale: locale,
).format(item.unitPriceInCents / 100);
final lineTotal = NumberFormat.simpleCurrency(
locale: locale,
).format(item.lineTotalInCents / 100);
final scheme = Theme.of(context).colorScheme;
return Padding(
@@ -207,4 +215,4 @@ class _ClosedTabItemRow extends StatelessWidget {
),
);
}
}
}
+4 -1
View File
@@ -3,6 +3,8 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:kooltab2/models/product.dart';
import '../../l10n/app_localizations.dart';
class ProductTile extends StatelessWidget {
final Product product;
final bool enabled;
@@ -20,6 +22,7 @@ class ProductTile extends StatelessWidget {
Widget build(BuildContext context) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
final l10n = AppLocalizations.of(context);
final outOfStock = product.stockQuantity <= 0;
final lowStock =
@@ -101,7 +104,7 @@ class ProductTile extends StatelessWidget {
borderRadius: BorderRadius.circular(999),
),
child: Text(
'OUT OF STOCK',
l10n.outOfStock,
style: TextStyle(
color: scheme.onError,
fontWeight: FontWeight.w800,
+4 -1
View File
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import '../../l10n/app_localizations.dart';
class SlideConfirm extends StatefulWidget {
final VoidCallback onConfirmed;
@@ -18,6 +20,7 @@ class _SlideConfirmState extends State<SlideConfirm> {
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
return SizedBox(
width: double.infinity,
@@ -37,7 +40,7 @@ class _SlideConfirmState extends State<SlideConfirm> {
children: [
Center(
child: Text(
_confirmed ? 'Closing tab...' : 'Slide to confirm closing',
_confirmed ? l10n.closingTab : l10n.slideToConfirmClosing,
style: TextStyle(
color: scheme.error,
fontWeight: FontWeight.w700,