0

I am using below code. I click some button and if my OTP match below method is getting called. and in that method i am calling bloc. Widget i am using is Statefulwidget.

void matchOtp() {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text(ALERT_TITLE),
            content: Text(OtpMatchSuccess),
            actions: <Widget>[
              IconButton(
                  icon: Icon(Icons.check),
                  onPressed: () {
                    if(OtpMatchSuccess == ALERT_OTP_MATCHED){
                    bloc.calledmethodinBloc(); // this method get called properly

                      StreamBuilder(
                          stream: bloc.usertype,
                          builder: (context, AsyncSnapshot<
                              ResponseModel> snapshot) {
                            print("INSIDE"); // My code does not go here. 


                            return Center(child: CircularProgressIndicator());
                          }
                      );

                      print("OUTSIDE");// My code moves outside the streambuilder. Is there any reason for that? 


                    }else{
                      Navigator.of(context, rootNavigator: true).pop('dialog');
                    }
                  })
            ],
          );
        });
  }
ios developer
  • 3,363
  • 3
  • 51
  • 111
  • 1
    You are creating an instance of stream builder in onPressed function but are not mounting it anywhere. Where do you intend to put the stream builder? If it's inside the button, you should make a button with its child as a stream builder. – Afridi Kayal Mar 28 '20 at 07:46
  • Thank you for the answer IconButton - is the button where i want to put it. But so do i have to add streambuilder as child of IconButton or as a child of actions: [ ? – ios developer Mar 28 '20 at 18:07
  • 1
    Actions are intended to be buttons. It's better to put the stream builder, as the child of the Button. Now icon buttons expect an icon as their child so you would probably want to use a FlatButton or RaisedButton instead. What I can figure out from your code is that you are trying to achieve that loading indicator the button shows while submitting an OTP. So clearly, The stream builder must be the child of the button – Afridi Kayal Mar 30 '20 at 10:50

0 Answers0