0

i want to pop showModalBottomSheet when i clicked the button of back in android mobile. this is my showModalBottomSheet example :

        showModalBottomSheet(
       context: contextt,
       useRootNavigator: true,
       isScrollControlled: true,
       isDismissible: true,
       enableDrag: true,
       shape: RoundedRectangleBorder(
       borderRadius: BorderRadius.vertical(top: Radius.circular(mySize.curve_large),
         ),),
       clipBehavior: Clip.antiAliasWithSaveLayer,
       builder: (contextt) {
          FocusScope.of(contextt).requestFocus(focusNode);
          return  SingleChildScrollView(
                physics: NeverScrollableScrollPhysics(),
                child: TextField(
                  controller: commentTextController,
                  cursorColor: theme.orange,
                  textAlignVertical: TextAlignVertical.center,
                  textAlign: TextAlign.center,
                  autofocus: true,
                  focusNode: focusNode,
                  maxLines: 2,
                  minLines: 1,
                  autocorrect: true,
                  enableInteractiveSelection: true,)); });},

if i just use show modal bottomsheet back button is work but in use text input in it . so when i click back , the sheet not pop. I use WillPopScope before my example widget "TextInput", but its not work :

WillPopScope(
 onWillPop: () async {
 FocusScope.of(contextt).requestFocus(FocusNode());
 Navigator.of(contextt).pop();
 return false;
 }, 

can anyone help me how can I do that?

and by the way, when I clicked the back button twice in a row, showModalBottomSheet popped. I want to do that with one click!.

user17838882
  • 93
  • 2
  • 14

1 Answers1

0
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
            child: const Text("Soo"),
            onPressed: () {
              showModalBottomSheet(
                constraints: BoxConstraints.tightFor(
                  height: 550,
                  width: MediaQuery.of(context).size.width,
                ),
                context: context,
                useRootNavigator: true,
                isScrollControlled: true,
                isDismissible: true,
                enableDrag: true,
                shape: const RoundedRectangleBorder(
                  borderRadius: BorderRadius.vertical(
                    top: Radius.circular(10),
                  ),
                ),
                clipBehavior: Clip.antiAliasWithSaveLayer,
                builder: (contextt) {
                  FocusScope.of(contextt).requestFocus(focusNode);
                  return SingleChildScrollView(
                    physics: const NeverScrollableScrollPhysics(),
                    child: TextField(
                      controller: commentTextController,
                      cursorColor: Colors.red,
                      textAlignVertical: TextAlignVertical.center,
                      textAlign: TextAlign.center,
                      autofocus: true,
                      focusNode: focusNode,
                      maxLines: 2,
                      minLines: 1,
                      autocorrect: true,
                      enableInteractiveSelection: true,
                    ),
                  );
                },
              );
            }),
      ),
    );
  }
DiyorbekDev
  • 706
  • 1
  • 5
  • 19