Untitled
unknown
plain_text
2 years ago
5.4 kB
11
Indexable
import 'package:dropdown_search/dropdown_search.dart'; import 'package:flutter/material.dart'; import 'package:sanad_flutter/core/config/app_localization.dart'; import 'package:sanad_flutter/core/config/sanad_colors.dart'; import 'package:sanad_flutter/core/widgets/custom_text.dart'; import '../config/global_variables.dart'; class CustomDropDownMenuWithSearch<T> extends StatelessWidget { final double? width; final double? height; final EdgeInsetsGeometry? margin; final EdgeInsetsGeometry? padding; final Color? color; final String hint; final Color? borderColor; final TextStyle? textStyle; final bool? isExpanded; final T? selectedItem; final void Function(T?)? onChanged; final String? label; final FormFieldValidator<T>? validator; final String Function(T?)? itemAsString; final List<T>? items; final TextStyle? labelStyle; final EdgeInsetsGeometry? labelPadding; final BorderRadiusGeometry? borderRadius; final bool? enabled; final InputDecoration? dropdownSearchDecoration; const CustomDropDownMenuWithSearch( {Key? key, this.label, this.labelPadding, this.labelStyle, this.textStyle, required this.items, required this.selectedItem, this.onChanged, this.borderColor, this.hint = "", this.color, this.width, this.height, this.margin, this.isExpanded, this.padding, this.validator, this.itemAsString, this.dropdownSearchDecoration, this.borderRadius, this.enabled}) : super(key: key); @override Widget build(BuildContext context) { return Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ if (label != null) CustomText( label!, style: labelStyle, padding: labelPadding, ), Container( width: width, height: height, margin: margin, decoration: dropdownSearchDecoration == null ? BoxDecoration( borderRadius: borderRadius ?? BorderRadius.circular(radius), color: color ?? selectColor(context, Colors.black12, Colors.white10), border: Border.all( color: color != null ? borderColor ?? Colors.transparent : selectColor( context, Colors.transparent, Colors.white), width: 0.5), ) : null, child: Padding( padding: padding ?? const EdgeInsets.symmetric(horizontal: 8.0), child: DropdownSearch<T>( // margin: const EdgeInsets.symmetric(vertical: 4), // hint: AppLocalization.of(context).getTranslatedValues('Cities'), // label: AppLocalization.of(context).getTranslatedValues('Cities'), // textStyle: Theme.of(context).textTheme.bodyText1!.copyWith( // fontSize: 15, // ), // labelPadding: EdgeInsets.only(bottom: 10.h), // color: Colors.transparent, // borderColor: selectColor(context, textFieldBorderLight, textFieldBorderDark), onChanged: onChanged, validator: validator, compareFn: (i1, i2) => i1 == i2, popupProps: PopupProps.dialog( showSelectedItems: true, emptyBuilder: (context, searchEntry) { return Center( child: Text(AppLocalization.of(context) .getTranslatedValues('no_data_available'))); }, interceptCallBacks: true, showSearchBox: true, searchFieldProps: TextFieldProps( decoration: InputDecoration( hintText: AppLocalization.of(context).getTranslatedValues(hint), hintStyle: const TextStyle(fontWeight: FontWeight.normal), ), )), onBeforePopupOpening: (selectedItem) async { return true; }, enabled: enabled ?? true, dropdownDecoratorProps: DropDownDecoratorProps( dropdownSearchDecoration: dropdownSearchDecoration ?? InputDecoration( hintText: AppLocalization.of(context) .getTranslatedValues(hint), hintStyle: const TextStyle(fontWeight: FontWeight.normal), border: InputBorder.none), ), dropdownButtonProps: DropdownButtonProps( icon: Icon( Icons.arrow_drop_down, size: 25, color: selectColor(context, textFieldDark, Colors.white54), )), itemAsString: itemAsString, items: items ?? [], selectedItem: selectedItem, ), ), ), ], ); } }
Editor is loading...