forked from eatvio/eatvio_app
134 lines
3.7 KiB
Dart
134 lines
3.7 KiB
Dart
import 'package:eatvio_app/data/models/selectionPopupModel/selection_popup_model.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class CustomDropDown extends StatelessWidget {
|
|
const CustomDropDown({
|
|
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,
|
|
});
|
|
|
|
final Alignment? alignment;
|
|
final double? width;
|
|
final FocusNode? focusNode;
|
|
final Widget? icon;
|
|
final bool? autofocus;
|
|
final TextStyle? textStyle;
|
|
final List<SelectionPopupModel>? 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<SelectionPopupModel>? 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<SelectionPopupModel>(
|
|
focusNode: focusNode ?? FocusNode(),
|
|
icon: Icon(Icons.keyboard_arrow_down_rounded),
|
|
autofocus: autofocus!,
|
|
value: value,
|
|
isDense: true,
|
|
isExpanded: true,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
color: Colors.black,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
items: items?.map((SelectionPopupModel item) {
|
|
return DropdownMenuItem<SelectionPopupModel>(
|
|
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(
|
|
labelStyle: TextStyle(
|
|
fontSize: 16,
|
|
color: Colors.black,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
hintText: hintText ?? "",
|
|
hintStyle: hintStyle ??
|
|
TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w400,
|
|
color: Colors.grey.shade400,
|
|
height: 1,
|
|
),
|
|
prefixIcon: prefix,
|
|
prefixIconConstraints: prefixConstraints,
|
|
suffixIcon: suffix,
|
|
isDense: true,
|
|
suffixIconConstraints: suffixConstraints,
|
|
contentPadding: EdgeInsets.symmetric(vertical: 16, horizontal: 12),
|
|
fillColor: Color(0xFFF6F6F6),
|
|
filled: filled,
|
|
border: OutlineInputBorder(
|
|
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
|
borderSide: BorderSide.none,
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
|
borderSide: BorderSide.none,
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
|
borderSide: BorderSide.none,
|
|
),
|
|
);
|
|
}
|
|
}
|