forked from eatvio/eatvio_app
145 lines
3.7 KiB
Dart
145 lines
3.7 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,
|
|
this.defaultValue,
|
|
}) : super(
|
|
key: key,
|
|
);
|
|
|
|
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? defaultValue;
|
|
|
|
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 SizedBox(
|
|
width: width ?? MediaQuery.of(context).size.width - 20,
|
|
child: DropdownButtonFormField<SelectionPopupModel>(
|
|
focusNode: focusNode ?? FocusNode(),
|
|
icon: icon,
|
|
autofocus: autofocus!,
|
|
isExpanded: true,
|
|
style: textStyle ?? Theme.of(context).textTheme.titleMedium,
|
|
items: items?.map((SelectionPopupModel item) {
|
|
return DropdownMenuItem<SelectionPopupModel>(
|
|
value: item,
|
|
child: Text(
|
|
item.title,
|
|
style: hintStyle ?? Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
);
|
|
}).toList(),
|
|
decoration: _buildInputDecoration(context),
|
|
validator: validator,
|
|
onChanged: onDropDownChanged,
|
|
),
|
|
);
|
|
}
|
|
|
|
void onDropDownChanged(value) {
|
|
onChanged!(value!);
|
|
}
|
|
|
|
InputDecoration _buildInputDecoration(BuildContext context) {
|
|
return InputDecoration(
|
|
hintText: hintText ?? "",
|
|
hintStyle: hintStyle ?? Theme.of(context).textTheme.titleMedium,
|
|
prefixIcon: prefix,
|
|
prefixIconConstraints: prefixConstraints,
|
|
suffixIcon: suffix,
|
|
suffixIconConstraints: suffixConstraints,
|
|
isDense: true,
|
|
contentPadding: contentPadding ??
|
|
EdgeInsets.only(
|
|
left: 6,
|
|
top: 6,
|
|
bottom: 6,
|
|
),
|
|
fillColor: fillColor ?? Theme.of(context).colorScheme.onPrimary,
|
|
filled: filled,
|
|
border: borderDecoration ??
|
|
OutlineInputBorder(
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
borderSide: BorderSide(color: appTheme.blueA400, width: 1),
|
|
),
|
|
enabledBorder: borderDecoration ??
|
|
OutlineInputBorder(
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
borderSide: BorderSide(color: appTheme.blueA400, width: 1),
|
|
),
|
|
focusedBorder: borderDecoration ??
|
|
OutlineInputBorder(
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
borderSide: BorderSide(color: appTheme.blueA400, width: 1),
|
|
),
|
|
);
|
|
}
|
|
}
|