2023-04-04 10:29:29 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:outbag_app/backend/room.dart';
|
|
|
|
|
|
|
|
class CategoryPicker extends StatelessWidget {
|
2023-04-04 20:28:26 +02:00
|
|
|
final List<RoomCategory> categories;
|
|
|
|
final int? selected;
|
|
|
|
final bool enabled;
|
|
|
|
final Function(int?)? onSelect;
|
2023-04-04 10:29:29 +02:00
|
|
|
|
|
|
|
// hint and label may differ depending on the screen
|
2023-04-04 20:28:26 +02:00
|
|
|
final String? hint;
|
|
|
|
final String? label;
|
2023-04-04 10:29:29 +02:00
|
|
|
|
2024-02-23 16:13:15 +01:00
|
|
|
final String server;
|
|
|
|
final String room;
|
|
|
|
|
2023-04-04 20:28:26 +02:00
|
|
|
const CategoryPicker(
|
2023-12-22 20:14:36 +01:00
|
|
|
{super.key,
|
2023-04-04 20:28:26 +02:00
|
|
|
required this.categories,
|
2024-02-23 16:13:15 +01:00
|
|
|
required this.server,
|
|
|
|
required this.room,
|
2023-04-04 10:29:29 +02:00
|
|
|
this.selected,
|
|
|
|
this.onSelect,
|
|
|
|
this.hint,
|
|
|
|
this.label,
|
|
|
|
this.enabled = true});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Padding(
|
2023-12-22 20:14:36 +01:00
|
|
|
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,
|
2024-02-23 16:13:15 +01:00
|
|
|
items: [...categories, RoomCategory.other(server, room, context)]
|
2023-12-22 20:14:36 +01:00
|
|
|
.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,
|
|
|
|
));
|
2023-04-04 10:29:29 +02:00
|
|
|
}
|
|
|
|
}
|