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.
This commit is contained in:
parent
86dac312a5
commit
456ed2836d
4 changed files with 42 additions and 34 deletions
|
@ -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 {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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<ShoppingListPage> {
|
|||
}
|
||||
|
||||
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)
|
||||
? [
|
||||
|
|
|
@ -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<ViewProductPage> {
|
|||
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):'')
|
||||
],
|
||||
))),
|
||||
|
||||
|
|
Loading…
Reference in a new issue