touch on the text field causes the screen to pop off of the stack in flutter

Viewed 182

I am new in flutter. I am facing a weird issue, when I touch on the text field then it gets the focus, and in the meanwhile, it causes the screen to pop off of the stack. and previous screen code gets executed that is written in stream builder. and because of this code execution, it again sends me to this screen. this is the code that takes me from the first screen to the second screen

enter image description here:-

StreamBuilder<Map<String,dynamic>>(
              stream: _blocForgotPass.isVerifiedOtp,
              builder: (context, snapshot) {

                var data = snapshot.data;

                print("nsdpassot");
                print(data);

                if(data != null){
                  var status = data["status"] as bool;
                  var userId = data["userId"] as int;

                  if(status){
                    SchedulerBinding.instance!.addPostFrameCallback((_) {
                      Navigator.push(context, MaterialPageRoute(builder: (context) => TakeNewPass(userId: userId)));
                    });
                  }
                }


                return SizedBox(
                  width: double.infinity,
                  child: ElevatedButton(
                      onPressed: verifyOtp,
                      child: Text("verify")),
                );
              }
          )

this is the code of my second screen:-

 return Scaffold(
  body: Padding(
    padding: const EdgeInsets.all(10.0),
    child: Column(
      children: [

        SizedBox(height: 20,),

        Container(
          width: double.infinity,
          alignment: Alignment.centerLeft,
          child: Image.asset("assets/back_arrow.png"),
        ),

        SizedBox(height: 40,),

        Text(
          "Reset Password",
          style: TextStyle(),
        ),

        SizedBox(height: 20,),

        Text(
          "Enter your new password ",
          style: TextStyle(),
        ),

        SizedBox(height: 40,),

        Container(
          width: double.infinity,
          alignment: Alignment.centerLeft,
          child: Text(
            "New Password",
            style: TextStyle(),
          ),
        ),


        Material(
          child: TextField(
            controller: _controllerPassword,
          ),
        ),

        SizedBox(height: 50,),

        Container(
          width: double.infinity,
          alignment: Alignment.centerLeft,
          child: Text(
            "Confirm Password",
            style: TextStyle(),
          ),
        ),

        Material(
          child: TextField(
            controller: _controllerConfirmedPassword,
          ),
        ),

        SizedBox(height: 50,),

        StreamBuilder<bool>(
            stream: _blocForgotPass.isPassReset,
            builder: (context, snapshot) {
              var data = snapshot.data;

              if(data == true){
                SchedulerBinding.instance!.addPostFrameCallback((_) {
                  Navigator.of(context, rootNavigator: true).pushReplacement(MaterialPageRoute(builder: (context) => new UserRole()));
                });
              }

              return SizedBox(
                width: double.infinity,
                child: ElevatedButton(
                    onPressed: resetPassword,
                    child: Text("Save")),
              );
            }
        )
      ],
    ),
  ),
);

when I touch on the text field then it behaves this way:-

0 Answers
Related