forked from eatvio/eatvio_app
132 lines
3.2 KiB
Dart
132 lines
3.2 KiB
Dart
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,
|
|
}) : super(
|
|
key: key,
|
|
);
|
|
|
|
final Alignment? alignment;
|
|
|
|
final double? width;
|
|
|
|
final FocusNode? focusNode;
|
|
|
|
final Widget? icon;
|
|
|
|
final bool? autofocus;
|
|
|
|
final TextStyle? textStyle;
|
|
|
|
final List<String>? 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 FormFieldValidator<String>? validator;
|
|
|
|
final Function(String)? onChanged;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return alignment != null
|
|
? Align(
|
|
alignment: alignment ?? Alignment.center,
|
|
child: dropDownWidget,
|
|
)
|
|
: dropDownWidget;
|
|
}
|
|
|
|
Widget get dropDownWidget => SizedBox(
|
|
width: width ?? double.maxFinite,
|
|
child: DropdownButtonFormField(
|
|
focusNode: focusNode ?? FocusNode(),
|
|
icon: icon,
|
|
autofocus: autofocus!,
|
|
items: items?.map<DropdownMenuItem<String>>((String value) {
|
|
return DropdownMenuItem<String>(
|
|
value: value,
|
|
child: Text(
|
|
value,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
);
|
|
}).toList(),
|
|
decoration: decoration,
|
|
validator: validator,
|
|
onChanged: (value) {
|
|
onChanged!(value.toString());
|
|
},
|
|
),
|
|
);
|
|
InputDecoration get decoration => InputDecoration(
|
|
hintText: hintText ?? "",
|
|
hintStyle: hintStyle,
|
|
prefixIcon: prefix,
|
|
prefixIconConstraints: prefixConstraints,
|
|
suffixIcon: suffix,
|
|
suffixIconConstraints: suffixConstraints,
|
|
isDense: true,
|
|
contentPadding: contentPadding ??
|
|
EdgeInsets.only(
|
|
left: 17,
|
|
top: 17,
|
|
bottom: 17,
|
|
),
|
|
fillColor: fillColor,
|
|
filled: filled,
|
|
border: borderDecoration ??
|
|
OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8.h),
|
|
borderSide: BorderSide.none,
|
|
),
|
|
enabledBorder: borderDecoration ??
|
|
OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8.h),
|
|
borderSide: BorderSide(color: Colors.grey, width: 1)),
|
|
focusedBorder: borderDecoration ??
|
|
OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(5.h),
|
|
borderSide: BorderSide(color: Colors.grey, width: 1),
|
|
),
|
|
);
|
|
}
|