showDropDown function
dynamic
showDropDown({
- required BuildContext context,
- required GlobalKey<
State< globalKey,StatefulWidget> > - required dynamic selectedValue(),
- required double rightSpace,
- required double childHeight,
- required TextStyle textStyle,
- TextAlign? textAlign,
- double? borderRadius,
- double? topHeight,
- Color? backGroundColor,
- LinearGradient? gradientBackGround,
- required List<
KeyValueModel> keyValueList, - required double childWidth,
Implementation
showDropDown({required BuildContext context,
required GlobalKey globalKey,
required Function(KeyValueModel) selectedValue,
required double rightSpace,
required double childHeight,
required TextStyle textStyle,
TextAlign? textAlign,
double? borderRadius,
double? topHeight,
Color? backGroundColor,
LinearGradient? gradientBackGround,
required List<KeyValueModel> keyValueList,
required double childWidth}){
RenderBox box =
globalKey.currentContext?.findRenderObject() as RenderBox;
Offset position = box.localToGlobal(Offset.zero);
showDialog(
barrierColor: Colors.transparent,
context: globalKey.currentContext!,
builder: (context){
return Stack(
children: [
Positioned(
top: position.dy + (MediaQuery.of(context).size.height>630?5:15) + (topHeight ?? 0),
right: rightSpace,
child: Container(
height: childHeight,
width: childWidth,
decoration: BoxDecoration(
gradient: gradientBackGround,
color: backGroundColor,
borderRadius: BorderRadius.circular(borderRadius ?? 10)),
child: ListView.builder(
padding:const EdgeInsets.all(15),
shrinkWrap: true,
itemCount: keyValueList.length,
itemBuilder: (context, index) {
return Bounce(
onPressed: () {
Navigator.pop(context);
selectedValue(KeyValueModel(itemId: keyValueList[index].itemId.toString(),itemName: keyValueList[index].itemName));
},
duration: const Duration(milliseconds: 500),
child: Padding(
padding: const EdgeInsets.all(5),
child: Text(keyValueList[index].itemName,
style: textStyle,
textAlign: textAlign ?? TextAlign.center,),
),
);
})),
),
],
);
});
}