actions-test/lib/components/product_picker.dart
Jakob Meier 47387bb395
Added basic Shopping List and Product list
including the ability to
add item into the shopping cart and remove them.

The click events have been implemented,
however the routes do not exist yet.

NOTE: The shopping list item info sheet is still missing
the unit type and value
and some more advanced options, like deleting the item
2023-04-04 10:29:29 +02:00

51 lines
1.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:outbag_app/backend/room.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class ProductPicker extends StatelessWidget {
List<RoomProduct> products = [];
int? selected;
bool enabled = true;
Function(int?)? onSelect;
// hint and label may differ depending on the screen
String? hint;
String? label;
ProductPicker(
{required this.products,
this.selected,
this.onSelect,
this.hint,
this.label,
this.enabled = true});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8),
child: DropdownMenu<int?>(
initialSelection: selected,
label: (label!=null)?Text(label!):null,
hintText: hint,
enabled: enabled,
onSelected: ((id) {
if (onSelect != null) {
onSelect!(id);
}
}),
dropdownMenuEntries: [
// entry for no product
DropdownMenuEntry(
value: null,
label: AppLocalizations.of(context)!.productNameNone,
),
// entry for every product
...products.map((product) => DropdownMenuEntry(
value: product.id,
label: product.name,
)),
],
));
}
}