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;
|
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 {
|
class SubUnit {
|
||||||
|
|
|
@ -367,6 +367,16 @@
|
||||||
"unitLength": "Length",
|
"unitLength": "Length",
|
||||||
"unitArea": "Area",
|
"unitArea": "Area",
|
||||||
|
|
||||||
|
"unitAmountDisplay": "{amount} Piece(s)",
|
||||||
|
"@unitAmountDisplay": {
|
||||||
|
"placeholders": {
|
||||||
|
"amount": {
|
||||||
|
"type": "String",
|
||||||
|
"example": "2.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
"inputUnitValueLabel": "Value",
|
"inputUnitValueLabel": "Value",
|
||||||
"selectUnitTypeLabel": "Unit Type",
|
"selectUnitTypeLabel": "Unit Type",
|
||||||
"selectUnitLabel": "Unit",
|
"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/category_picker.dart';
|
||||||
import 'package:outbag_app/components/labeled_divider.dart';
|
import 'package:outbag_app/components/labeled_divider.dart';
|
||||||
import 'package:outbag_app/components/product_picker.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:outbag_app/tools/fetch_wrapper.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
@ -319,15 +320,15 @@ class _ShoppingListPageState extends State<ShoppingListPage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ShoppingListItem extends StatelessWidget {
|
class ShoppingListItem extends StatelessWidget {
|
||||||
String name;
|
final String name;
|
||||||
RoomCategory category;
|
final RoomCategory category;
|
||||||
String description;
|
final String description;
|
||||||
bool inCart;
|
final bool inCart;
|
||||||
final Key _key;
|
final Key _key;
|
||||||
Function()? onDismiss;
|
final Function()? onDismiss;
|
||||||
Function()? onTap;
|
final Function()? onTap;
|
||||||
|
|
||||||
ShoppingListItem(
|
const ShoppingListItem(
|
||||||
{required this.name,
|
{required this.name,
|
||||||
required this.category,
|
required this.category,
|
||||||
required this.inCart,
|
required this.inCart,
|
||||||
|
@ -405,15 +406,7 @@ class ShoppingListItemInfo extends StatelessWidget {
|
||||||
Text(item.name, style: textTheme.headlineLarge),
|
Text(item.name, style: textTheme.headlineLarge),
|
||||||
Text(item.description, style: textTheme.titleMedium),
|
Text(item.description, style: textTheme.titleMedium),
|
||||||
CategoryChip(category: category,),
|
CategoryChip(category: category,),
|
||||||
ProductPicker(
|
Text(Unit.fromId(item.unit).display(context, item.value))
|
||||||
label:
|
|
||||||
AppLocalizations.of(context)!.selectLinkedProductLabel,
|
|
||||||
help: AppLocalizations.of(context)!.selectLinkedProductHelp,
|
|
||||||
products: products,
|
|
||||||
selected: item.link,
|
|
||||||
enabled: false)
|
|
||||||
|
|
||||||
// TODO: show more info
|
|
||||||
]))),
|
]))),
|
||||||
...(item.link != null)
|
...(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/room.dart';
|
||||||
import 'package:outbag_app/backend/user.dart';
|
import 'package:outbag_app/backend/user.dart';
|
||||||
import 'package:outbag_app/components/category_chip.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:outbag_app/tools/fetch_wrapper.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
@ -145,12 +145,7 @@ class _ViewProductPageState extends State<ViewProductPage> {
|
||||||
style: textTheme.titleMedium),
|
style: textTheme.titleMedium),
|
||||||
Text(product?.ean ?? ''),
|
Text(product?.ean ?? ''),
|
||||||
CategoryChip(category: categories[product?.category]),
|
CategoryChip(category: categories[product?.category]),
|
||||||
ProductPicker(
|
Text(product!=null?Unit.fromId(product!.defaultUnit).display(context, product!.defaultValue):'')
|
||||||
label: AppLocalizations.of(context)!
|
|
||||||
.selectParentProductLabel,
|
|
||||||
products: products,
|
|
||||||
selected: product?.parent,
|
|
||||||
enabled: false)
|
|
||||||
],
|
],
|
||||||
))),
|
))),
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue