showDropDown function

dynamic showDropDown({
  1. required BuildContext context,
  2. required GlobalKey<State<StatefulWidget>> globalKey,
  3. required dynamic selectedValue(
    1. KeyValueModel
    ),
  4. required double rightSpace,
  5. required double childHeight,
  6. required TextStyle textStyle,
  7. TextAlign? textAlign,
  8. double? borderRadius,
  9. double? topHeight,
  10. Color? backGroundColor,
  11. LinearGradient? gradientBackGround,
  12. required List<KeyValueModel> keyValueList,
  13. 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,),
                          ),
                        );
                      })),
            ),
          ],
        );
      });
}