47387bb395
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
57 lines
1.6 KiB
Dart
57 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:outbag_app/backend/room.dart';
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
class CategoryPicker extends StatelessWidget {
|
|
List<RoomCategory> categories = [];
|
|
int? selected;
|
|
bool enabled = true;
|
|
Function(int?)? onSelect;
|
|
|
|
// hint and label may differ depending on the screen
|
|
String? hint;
|
|
String? label;
|
|
|
|
CategoryPicker(
|
|
{required this.categories,
|
|
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,
|
|
enabled: enabled,
|
|
hintText: hint,
|
|
label: (label!=null)?Text(label!):null,
|
|
onSelected: ((id) {
|
|
if (onSelect != null) {
|
|
onSelect!(id);
|
|
}
|
|
}),
|
|
dropdownMenuEntries: [
|
|
// entry for every categry
|
|
...categories.map((category) => DropdownMenuEntry(
|
|
value: category.id,
|
|
label: category.name,
|
|
trailingIcon: Icon(
|
|
Icons.square_rounded,
|
|
color: category.color,
|
|
))),
|
|
// entry for default ("other") category
|
|
DropdownMenuEntry(
|
|
value: null,
|
|
label: AppLocalizations.of(context)!.categoryNameOther,
|
|
trailingIcon: Icon(
|
|
Icons.square_rounded,
|
|
color: RoomCategory.other(context).color,
|
|
))
|
|
],
|
|
));
|
|
}
|
|
}
|