feat: add localisation
This commit is contained in:
@@ -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)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user