actions-test/lib/components/category_picker.dart
Jakob Meier 5cd21c8adf
Added Combined new/edit and view product screen
Similarily to categories and rooms,
the edit product screen is reused as a new-room screen,
which is especially easy, because the user is unable to select
the product id themselves.
NOTE: the dynamic value-unit input is still missing some "subunits"

The view product screen has links to the edit product page,
the view parent page (if available) and a not yet functional
view children screen.
NOTE: The parent product display should be restricted in width,
and the screen is missing value/unit information.
2023-04-04 20:28:26 +02:00

58 lines
1.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:outbag_app/backend/room.dart';
class CategoryPicker extends StatelessWidget {
final List<RoomCategory> categories;
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;
const CategoryPicker(
{super.key,
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: DropdownButtonFormField<int?>(
hint: hint==null?null:Text(hint!),
decoration: InputDecoration(
label: label==null?null:Text(label!),
border: const OutlineInputBorder(),
prefixIcon: const Icon(Icons.category)
),
value: selected,
items: [
...categories,
RoomCategory.other(context)
].map((category)=>DropdownMenuItem<int?>(
value: category.id,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(category.name),
Icon(Icons.square_rounded,
color:category.color,
size: 32)
]
),
)).toList(),
onChanged: enabled?(cid) {
if (onSelect != null) {
onSelect!(cid);
}
}:null,
));
}
}