2024-09-27 15:30:39 +02:00
|
|
|
import 'package:ambito/src/widgets/form/form_widget.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
|
|
|
|
|
|
|
class FieldDropdown extends FormWidgetField {
|
|
|
|
FieldDropdown(
|
|
|
|
{required this.name,
|
|
|
|
required this.label,
|
|
|
|
required this.filterValue,
|
|
|
|
required this.onClear,
|
|
|
|
required this.onSelected,
|
|
|
|
required this.entries});
|
|
|
|
|
|
|
|
final String name;
|
|
|
|
final String label;
|
|
|
|
final String? filterValue;
|
|
|
|
final VoidCallback onClear;
|
|
|
|
final void Function(String?) onSelected;
|
|
|
|
final List<String> entries;
|
|
|
|
|
2024-10-29 16:15:11 +01:00
|
|
|
@override
|
2024-09-27 15:30:39 +02:00
|
|
|
FormBuilderField get() {
|
|
|
|
return FormBuilderDropdown<String>(
|
|
|
|
name: name,
|
|
|
|
initialValue: filterValue,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: label,
|
|
|
|
prefix: IconButton(
|
|
|
|
icon: const Icon(Icons.cancel_outlined),
|
|
|
|
onPressed: onClear,
|
|
|
|
),
|
|
|
|
hintText: label,
|
|
|
|
),
|
|
|
|
onReset: onClear,
|
|
|
|
onChanged: onSelected,
|
|
|
|
items: entries
|
|
|
|
.map(
|
|
|
|
(entry) => DropdownMenuItem(
|
|
|
|
value: entry,
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: Text(entry),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|