2024-02-06 16:28:51 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_registration/flutter_registration.dart';
|
|
|
|
|
|
|
|
class AuthDropdownField extends AuthField {
|
|
|
|
AuthDropdownField({
|
|
|
|
required super.name,
|
|
|
|
required this.items,
|
|
|
|
required this.onChanged,
|
|
|
|
this.dropdownDecoration,
|
|
|
|
this.padding = const EdgeInsets.all(8.0),
|
|
|
|
this.textStyle,
|
|
|
|
this.icon = const Icon(Icons.keyboard_arrow_down),
|
|
|
|
required super.value,
|
2024-04-03 11:23:48 +02:00
|
|
|
});
|
2024-02-06 16:28:51 +01:00
|
|
|
|
|
|
|
final List<String> items;
|
|
|
|
final Function(String?) onChanged;
|
|
|
|
String? selectedValue;
|
|
|
|
final InputDecoration? dropdownDecoration;
|
|
|
|
final EdgeInsets padding;
|
|
|
|
final TextStyle? textStyle;
|
|
|
|
final Icon icon;
|
|
|
|
|
|
|
|
@override
|
2024-02-09 18:36:22 +01:00
|
|
|
Widget build(BuildContext context, Function onValueChanged) {
|
2024-02-06 16:28:51 +01:00
|
|
|
return Padding(
|
|
|
|
padding: padding,
|
|
|
|
child: DropdownButtonFormField<String>(
|
|
|
|
icon: icon,
|
|
|
|
style: textStyle,
|
2024-04-03 11:23:48 +02:00
|
|
|
value: value,
|
2024-02-06 16:28:51 +01:00
|
|
|
decoration: dropdownDecoration,
|
|
|
|
items: items.map((String value) {
|
|
|
|
return DropdownMenuItem<String>(
|
|
|
|
value: value,
|
|
|
|
child: Text(value),
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
onChanged: (newValue) {
|
|
|
|
selectedValue = newValue;
|
|
|
|
onChanged(newValue);
|
2024-04-03 11:23:48 +02:00
|
|
|
onValueChanged(newValue);
|
2024-02-06 16:28:51 +01:00
|
|
|
},
|
|
|
|
validator: (value) {
|
|
|
|
if (validators.isNotEmpty) {
|
|
|
|
for (var validator in validators) {
|
|
|
|
var output = validator(value);
|
|
|
|
if (output != null) {
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|