overflow at the bottom of the Get.defaultDialog() when the keyboard is open

Viewed 26

I am using Get.defaultDialog() with a ListView.Builder and a TextformField() at the bottom of the dialog. The issue is whenever I open the keyboard, The bottom of the dialog box is getting overflowed.

I have tried various ways, But nothing is working for me.

One of the solutions I have tried

Other solutions that I tried are all similar to the above one.

If I give double.maxFinite then the dialog box covers the whole screen. I don't want that to happen.

What I want to achieve is, The height should not exceed the content of the dialog.

This is My Code for dialog() :

    void cancelTask() {
    RxInt selectedreason = 0.obs;
    String cancelReason = kCancelReasonList[0].name;
    TextEditingController cancelReasonController = TextEditingController();
    Get.defaultDialog(
      title: kLanguageList!.value.clearTask,
      titleStyle: TextStyle(
        color: kBlack,
        fontSize: kTextScaleFactor * 18,
        fontWeight: FontWeight.bold,
      ),
      textConfirm: kLanguageList!.value.ok,
      confirmTextColor: kBlack,
      textCancel: kLanguageList!.value.cancel,
      cancelTextColor: kOrange,
      buttonColor: Colors.transparent,
      contentPadding: EdgeInsets.symmetric(
          vertical: kWidth * 0.02, horizontal: kWidth * 0.02),
      onConfirm: () {},
      content: SingleChildScrollView(
        child: Obx(
          () => AnimatedContainer(
            duration: selectedreason.value != 3
                ? const Duration(seconds: 1)
                : const Duration(milliseconds: 500),
            width: kWidth * 0.7,
            height:
                selectedreason.value != 3 ? kHeight * 0.285 : kHeight * 0.37,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                ListView.builder(
                  shrinkWrap: true,
                  itemCount: kCancelReasonList.length,
                  itemBuilder: (context, index) {
                    return RadioListTile(
                      toggleable: true,
                      title: CommonText(
                        text: kCancelReasonList[index].name.obs,
                        size: 1,
                        boldText: false,
                      ),
                      value: index,
                      groupValue: selectedreason.value,
                      onChanged: (int? reason) {
                        selectedreason.value = reason!;
                        cancelReason = kCancelReasonList[index].name;
                      },
                    );
                  },
                ),
                RadioListTile(
                  title: CommonText(
                    text: kLanguageList!.value.other.obs,
                    size: 1,
                    boldText: false,
                  ),
                  value: 3,
                  groupValue: selectedreason.value,
                  onChanged: (int? reason) {
                    selectedreason.value = reason!;
                    if (reason == 3) {
                      cancelReasonController.text = "";
                      cancelReason = "";
                    }
                  },
                ),
                Obx(() => AnimatedContainer(
                      duration: selectedreason.value == 3
                          ? const Duration(seconds: 1)
                          : const Duration(milliseconds: 500),
                      curve: Curves.fastOutSlowIn,
                      height: selectedreason.value == 3 ? kHeight * 0.085 : 0,
                      child: selectedreason.value == 3
                          ? CommonTextFormField(
                              controller: cancelReasonController,
                              onChanged: (reason) {
                                if (reason.isNotEmpty) {
                                  cancelReason = reason;
                                }
                              },
                              keyboardType: TextInputType.text,
                              focusBorderColor: kOrange,
                            )
                          : const SizedBox.shrink(),
                    ))
              ],
            ),
          ),
        ),
      ),
    );
  }
1 Answers

Try to add resizeToAvoidBottomInset: false, property inside Scaffold widget.

Related