test base project
This commit is contained in:
@@ -0,0 +1,199 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../Utils/color_constants.dart';
|
||||
import '../Utils/image_constant.dart';
|
||||
import '../Utils/size_utils.dart';
|
||||
|
||||
class CustomDropDown extends StatelessWidget {
|
||||
CustomDropDown(
|
||||
{this.shape,
|
||||
this.padding,
|
||||
this.variant,
|
||||
this.fontStyle,
|
||||
this.alignment,
|
||||
this.width,
|
||||
this.margin,
|
||||
this.focusNode,
|
||||
this.icon,
|
||||
this.hintText,
|
||||
this.prefix,
|
||||
this.prefixConstraints,
|
||||
this.items,
|
||||
this.onChanged,
|
||||
this.validator});
|
||||
|
||||
DropDownShape? shape;
|
||||
|
||||
DropDownPadding? padding;
|
||||
|
||||
DropDownVariant? variant;
|
||||
|
||||
DropDownFontStyle? fontStyle;
|
||||
|
||||
Alignment? alignment;
|
||||
|
||||
double? width;
|
||||
|
||||
EdgeInsetsGeometry? margin;
|
||||
|
||||
FocusNode? focusNode;
|
||||
|
||||
Widget? icon;
|
||||
|
||||
String? hintText;
|
||||
|
||||
Widget? prefix;
|
||||
|
||||
BoxConstraints? prefixConstraints;
|
||||
|
||||
List<String>? items;
|
||||
|
||||
Function(String)? onChanged;
|
||||
|
||||
FormFieldValidator<String>? validator;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return alignment != null
|
||||
? Align(
|
||||
alignment: alignment ?? Alignment.center,
|
||||
child: _buildDropDownWidget(),
|
||||
)
|
||||
: _buildDropDownWidget();
|
||||
}
|
||||
|
||||
_buildDropDownWidget() {
|
||||
return Container(
|
||||
width: width ?? double.maxFinite,
|
||||
margin: margin,
|
||||
child: DropdownButtonFormField(
|
||||
focusNode: focusNode,
|
||||
icon: icon,
|
||||
style: _setFontStyle(),
|
||||
decoration: _buildDecoration(),
|
||||
items: items?.map<DropdownMenuItem<String>>((String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(
|
||||
value,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
onChanged!(value.toString());
|
||||
},
|
||||
validator: validator,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_buildDecoration() {
|
||||
return InputDecoration(
|
||||
hintText: hintText ?? "",
|
||||
hintStyle: _setFontStyle(),
|
||||
border: _setBorderStyle(),
|
||||
enabledBorder: _setBorderStyle(),
|
||||
focusedBorder: _setBorderStyle(),
|
||||
prefixIcon: prefix,
|
||||
prefixIconConstraints: prefixConstraints,
|
||||
fillColor: _setFillColor(),
|
||||
filled: _setFilled(),
|
||||
isDense: true,
|
||||
contentPadding: _setPadding(),
|
||||
);
|
||||
}
|
||||
|
||||
_setFontStyle() {
|
||||
switch (fontStyle) {
|
||||
case DropDownFontStyle.GilroyRegular16:
|
||||
return TextStyle(
|
||||
color: ColorConstant.blueGray200,
|
||||
fontSize: getFontSize(
|
||||
16,
|
||||
),
|
||||
fontFamily: 'Gilroy',
|
||||
fontWeight: FontWeight.w400,
|
||||
);
|
||||
default:
|
||||
return TextStyle(
|
||||
color: ColorConstant.blueGray900,
|
||||
fontSize: getFontSize(
|
||||
16,
|
||||
),
|
||||
fontFamily: 'Gilroy',
|
||||
fontWeight: FontWeight.w600,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_setOutlineBorderRadius() {
|
||||
switch (shape) {
|
||||
default:
|
||||
return BorderRadius.circular(
|
||||
getHorizontalSize(
|
||||
6.00,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_setBorderStyle() {
|
||||
switch (variant) {
|
||||
case DropDownVariant.None:
|
||||
return InputBorder.none;
|
||||
default:
|
||||
return OutlineInputBorder(
|
||||
borderRadius: _setOutlineBorderRadius(),
|
||||
borderSide: BorderSide(
|
||||
color: ColorConstant.blueGray100,
|
||||
width: 1,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_setFillColor() {
|
||||
switch (variant) {
|
||||
default:
|
||||
return ColorConstant.whiteA700;
|
||||
}
|
||||
}
|
||||
|
||||
_setFilled() {
|
||||
switch (variant) {
|
||||
case DropDownVariant.None:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
_setPadding() {
|
||||
switch (padding) {
|
||||
default:
|
||||
return getPadding(
|
||||
left: 10,
|
||||
top: 10,
|
||||
bottom: 10,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum DropDownShape {
|
||||
RoundedBorder6,
|
||||
}
|
||||
|
||||
enum DropDownPadding {
|
||||
PaddingT10,
|
||||
}
|
||||
|
||||
enum DropDownVariant {
|
||||
None,
|
||||
OutlineBluegray100,
|
||||
}
|
||||
|
||||
enum DropDownFontStyle {
|
||||
GilroySemiBold16,
|
||||
GilroyRegular16,
|
||||
}
|
||||
Reference in New Issue
Block a user