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 ProductPicker extends StatelessWidget {
|
|
final List<RoomProduct> products;
|
|
final int? selected;
|
|
final bool enabled;
|
|
final Function(int?)? onSelect;
|
|
|
|
// hint and label may differ depending on the screen
|
|
final String? hint;
|
|
final String? label;
|
|
final String? help;
|
|
|
|
const ProductPicker(
|
|
{super.key,
|
|
required this.products,
|
|
this.selected,
|
|
this.onSelect,
|
|
this.hint,
|
|
this.help,
|
|
this.label,
|
|
this.enabled = true});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: DropdownButtonFormField<int?>(
|
|
hint: hint == null ? null : Text(hint!),
|
|
decoration: InputDecoration(
|
|
label: label == null ? null : Text(label!),
|
|
border: const OutlineInputBorder(),
|
|
prefixIcon: const Icon(Icons.inventory_2),
|
|
helperText: help),
|
|
value: selected,
|
|
items: [
|
|
// "no product" entry
|
|
DropdownMenuItem<int?>(
|
|
value: null,
|
|
child: Text(AppLocalizations.of(context)!.productNameNone),
|
|
),
|
|
// other products
|
|
...products.map((product) => DropdownMenuItem<int?>(
|
|
value: product.id, child: Text(product.name)))
|
|
],
|
|
onChanged: enabled
|
|
? (pid) {
|
|
if (onSelect != null) {
|
|
onSelect!(pid);
|
|
}
|
|
}
|
|
: null,
|
|
));
|
|
}
|
|
}
|