74 lines
2.0 KiB
Dart
74 lines
2.0 KiB
Dart
import 'package:dropdown_search/dropdown_search.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class DropDownWidget<T> extends StatelessWidget {
|
|
final List<T> item;
|
|
final T selectItem;
|
|
final void Function(T?) onChanged;
|
|
final bool Function(T, T)? compareFunction;
|
|
final String Function(T)? toStr;
|
|
final EdgeInsets? padding;
|
|
final EdgeInsetsGeometry? margin;
|
|
final String? Function(T?)? validator;
|
|
// Future<List<String>> Function(String)? asyncItems;
|
|
|
|
const DropDownWidget(
|
|
{super.key,
|
|
required this.item,
|
|
required this.selectItem,
|
|
required this.onChanged,
|
|
this.compareFunction,
|
|
this.validator,
|
|
this.toStr,
|
|
this.padding,
|
|
this.margin
|
|
// required this.asyncItems
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DropdownSearch<T>(
|
|
// asyncItems:asyncItems ,
|
|
validator: validator,
|
|
dropdownButtonProps: DropdownButtonProps(
|
|
|
|
// color: AppColors.secondaryColor,
|
|
icon: const Icon(
|
|
Icons.arrow_drop_down,
|
|
size: 45,
|
|
),
|
|
// alignment: Alignment.centerLeft,
|
|
padding: padding ?? const EdgeInsets.all(8)
|
|
|
|
// iconSize: 50
|
|
),
|
|
|
|
popupProps: const PopupProps.menu(
|
|
fit: FlexFit.loose,
|
|
// showSelectedItems: true,
|
|
),
|
|
|
|
items: item,
|
|
compareFn: compareFunction,
|
|
itemAsString: toStr,
|
|
|
|
dropdownDecoratorProps: DropDownDecoratorProps(
|
|
textAlignVertical: TextAlignVertical.center,
|
|
textAlign: TextAlign.left,
|
|
baseStyle: const TextStyle(
|
|
fontSize: 16,
|
|
// fontWeight: FontWeight,
|
|
),
|
|
dropdownSearchDecoration: InputDecoration(
|
|
contentPadding: margin,
|
|
helperStyle: const TextStyle(color: Colors.red),
|
|
hintStyle: const TextStyle(color: Colors.red),
|
|
border: InputBorder.none,
|
|
),
|
|
),
|
|
onChanged: onChanged,
|
|
selectedItem: selectItem,
|
|
);
|
|
}
|
|
}
|