authsec_flutter_new/base_project/lib/widgets/custom_dropdownfield.dart

49 lines
1.4 KiB
Dart
Raw Permalink Normal View History

2025-09-06 19:21:52 +05:30
import 'package:flutter/material.dart';
class CustomDropdownField<T> extends StatelessWidget {
final String? hintText;
final List<DropdownMenuItem<T>> items;
final T? value;
final void Function(T?)? onChanged;
final void Function(T?)? onSaved;
final String? Function(T?)? validator;
const CustomDropdownField(
{super.key, this.hintText,
required this.items,
this.value,
this.onChanged,
this.onSaved,
this.validator});
@override
Widget build(BuildContext context) {
return FormField<T>(
builder: (FormFieldState<T> state) {
return InputDecorator(
decoration: InputDecoration(
enabledBorder: InputBorder.none,
hintStyle: TextStyle(color: Colors.black.withOpacity(.4)),
contentPadding: const EdgeInsets.only(left: 10, right: 10, bottom: 6),
errorText: state.errorText,
),
child: DropdownButtonFormField<T>(
value: value,
items: items,
onChanged: (T? newValue) {
state.didChange(newValue);
if (onChanged != null) {
onChanged!(newValue);
}
},
onSaved: onSaved,
hint: Text(hintText ?? ''),
style: TextStyle(color: Colors.black.withOpacity(.8)),
//isExpanded: true,
validator: validator),
);
},
);
}
}