52 lines
1.3 KiB
Dart
52 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,
|
||
|
)),
|
||
|
],
|
||
|
));
|
||
|
}
|
||
|
}
|