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