import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; class CustomDropDown extends StatelessWidget { CustomDropDown({ Key? key, this.alignment, this.width, this.focusNode, this.icon, this.autofocus = true, this.textStyle, this.items, this.hintText, this.hintStyle, this.prefix, this.prefixConstraints, this.suffix, this.suffixConstraints, this.contentPadding, this.borderDecoration, this.fillColor, this.filled = true, this.validator, this.onChanged, this.value, }) : super( key: key, ); final Alignment? alignment; final double? width; final FocusNode? focusNode; final Widget? icon; final bool? autofocus; final TextStyle? textStyle; final List? items; final String? hintText; final TextStyle? hintStyle; final Widget? prefix; final BoxConstraints? prefixConstraints; final Widget? suffix; final BoxConstraints? suffixConstraints; final EdgeInsets? contentPadding; final InputBorder? borderDecoration; final Color? fillColor; final bool? filled; final SelectionPopupModel? value; final FormFieldValidator? validator; final Function(SelectionPopupModel)? onChanged; @override Widget build(BuildContext context) { return alignment != null ? Align( alignment: alignment ?? Alignment.center, child: _buildDropDownWidget(context), ) : _buildDropDownWidget(context); } _buildDropDownWidget(BuildContext context) { return DropdownButtonFormField( focusNode: focusNode ?? FocusNode(), icon: Icon(Icons.keyboard_arrow_down_rounded), autofocus: autofocus!, value: value, isExpanded: true, style: textStyle ?? TextStyle( fontSize: 16, fontWeight: FontWeight.w400, ), items: items?.map((SelectionPopupModel item) { return DropdownMenuItem( value: item, child: Text( item.title, style: hintStyle ?? TextStyle( fontSize: 16, fontWeight: FontWeight.w400, color: Colors.black, ), ), ); }).toList(), decoration: _buildInputDecoration(context), validator: validator, onChanged: onDropDownChanged, ); } void onDropDownChanged(value) { onChanged!(value!); } InputDecoration _buildInputDecoration(BuildContext context) { return InputDecoration( hintText: hintText ?? "", hintStyle: hintStyle ?? TextStyle( fontSize: 16, fontWeight: FontWeight.w400, color: Colors.grey.shade400, ), prefixIcon: prefix, prefixIconConstraints: prefixConstraints, suffixIcon: suffix, suffixIconConstraints: suffixConstraints, isDense: true, contentPadding: contentPadding ?? EdgeInsets.all(8), fillColor: fillColor ?? Theme.of(context).colorScheme.onPrimary, filled: filled, border: borderDecoration ?? OutlineInputBorder( borderRadius: BorderRadius.circular(8), borderSide: BorderSide( color: Colors.grey.shade400, width: 1, ), ), enabledBorder: borderDecoration ?? OutlineInputBorder( borderRadius: BorderRadius.circular(8), borderSide: BorderSide( color: Colors.grey.shade400, width: 1, ), ), focusedBorder: borderDecoration ?? OutlineInputBorder( borderRadius: BorderRadius.circular(8), borderSide: BorderSide( color: appTheme.blueA400, width: 1, ), ), ); } }