From 456ed2836df72f79a875d8c3ea626fc7a6ee4ad9 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 5 Apr 2023 10:22:43 +0200 Subject: [PATCH] Added unit/value display to view-item and view-product. NOTE: Whilst flutter supports plural-translations, we are not using them for unitAmountDisplay, because it is hard to choose the fitting one, for doubles. --- lib/components/value_unit_input.dart | 10 ++++++ lib/l10n/app_en.arb | 10 ++++++ lib/screens/room/pages/list.dart | 47 ++++++++++++---------------- lib/screens/room/products/view.dart | 9 ++---- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/lib/components/value_unit_input.dart b/lib/components/value_unit_input.dart index 2201fc3..09a2057 100644 --- a/lib/components/value_unit_input.dart +++ b/lib/components/value_unit_input.dart @@ -126,6 +126,16 @@ class Unit { return TextInputType.number; } } + + String display(BuildContext context, String value) { + if (type == UnitType.text) { + return value; + } else if (type == UnitType.amount) { + return AppLocalizations.of(context)!.unitAmountDisplay(value); + } + + return '$value ${subUnits[defaultSubUnit!].name}'; + } } class SubUnit { diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 9d92cc0..b046ea4 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -367,6 +367,16 @@ "unitLength": "Length", "unitArea": "Area", + "unitAmountDisplay": "{amount} Piece(s)", + "@unitAmountDisplay": { + "placeholders": { + "amount": { + "type": "String", + "example": "2.5" + } + } + }, + "inputUnitValueLabel": "Value", "selectUnitTypeLabel": "Unit Type", "selectUnitLabel": "Unit", diff --git a/lib/screens/room/pages/list.dart b/lib/screens/room/pages/list.dart index a0be616..0d3a9a9 100644 --- a/lib/screens/room/pages/list.dart +++ b/lib/screens/room/pages/list.dart @@ -8,6 +8,7 @@ import 'package:outbag_app/components/category_chip.dart'; import 'package:outbag_app/components/category_picker.dart'; import 'package:outbag_app/components/labeled_divider.dart'; import 'package:outbag_app/components/product_picker.dart'; +import 'package:outbag_app/components/value_unit_input.dart'; import 'package:outbag_app/tools/fetch_wrapper.dart'; import 'package:provider/provider.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -319,15 +320,15 @@ class _ShoppingListPageState extends State { } class ShoppingListItem extends StatelessWidget { - String name; - RoomCategory category; - String description; - bool inCart; + final String name; + final RoomCategory category; + final String description; + final bool inCart; final Key _key; - Function()? onDismiss; - Function()? onTap; + final Function()? onDismiss; + final Function()? onTap; - ShoppingListItem( + const ShoppingListItem( {required this.name, required this.category, required this.inCart, @@ -361,17 +362,17 @@ class ShoppingListItem extends StatelessWidget { child: Opacity( opacity: inCart?0.5:1.0, child: ListTile( - title: Text(name), - subtitle: Text(description), - trailing: CategoryChip( - category: category, - ), - onTap: () { - if (onTap != null) { - onTap!(); - } - }, - )), + title: Text(name), + subtitle: Text(description), + trailing: CategoryChip( + category: category, + ), + onTap: () { + if (onTap != null) { + onTap!(); + } + }, + )), ); } } @@ -405,15 +406,7 @@ class ShoppingListItemInfo extends StatelessWidget { Text(item.name, style: textTheme.headlineLarge), Text(item.description, style: textTheme.titleMedium), CategoryChip(category: category,), - ProductPicker( - label: - AppLocalizations.of(context)!.selectLinkedProductLabel, - help: AppLocalizations.of(context)!.selectLinkedProductHelp, - products: products, - selected: item.link, - enabled: false) - - // TODO: show more info + Text(Unit.fromId(item.unit).display(context, item.value)) ]))), ...(item.link != null) ? [ diff --git a/lib/screens/room/products/view.dart b/lib/screens/room/products/view.dart index f2df009..d1d8166 100644 --- a/lib/screens/room/products/view.dart +++ b/lib/screens/room/products/view.dart @@ -6,7 +6,7 @@ import 'package:outbag_app/backend/request.dart'; import 'package:outbag_app/backend/room.dart'; import 'package:outbag_app/backend/user.dart'; import 'package:outbag_app/components/category_chip.dart'; -import 'package:outbag_app/components/product_picker.dart'; +import 'package:outbag_app/components/value_unit_input.dart'; import 'package:outbag_app/tools/fetch_wrapper.dart'; import 'package:provider/provider.dart'; @@ -145,12 +145,7 @@ class _ViewProductPageState extends State { style: textTheme.titleMedium), Text(product?.ean ?? ''), CategoryChip(category: categories[product?.category]), - ProductPicker( - label: AppLocalizations.of(context)! - .selectParentProductLabel, - products: products, - selected: product?.parent, - enabled: false) + Text(product!=null?Unit.fromId(product!.defaultUnit).display(context, product!.defaultValue):'') ], ))),