skip to Main Content

I have a request to the server, when I use FutureBuilder, the ConnectionState.waiting section, I want to use a custom dialog, but after ConnectionState.done, this dialog does not close, it does not even do Navigator.pop(context).
enter image description here
enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    Unfortunately, it is not possible to disable Alert Dialog using object orientation, and I designed dialogs on a separate page, and Navigator.pop() does not work, but with this method, I achieved my desired result.

      FutureBuilder(
       future: _futureEditName,
       builder: (context,snapshot){
          if(snapshot.connectionState == ConnectionState.waiting){
              ShowWaitingDialog(context,true);
    
          }else if(snapshot.connectionState == ConnectionState.done && snapshot.hasData){
             ShowWaitingDialog(context,false)
          }
       }
    
    );
    

    show and dismiss Alert Dialog

    ShowWaitingDialog(BuildContext context,bool show) {
    showDialog(
      context: context,
      builder: (context) {
        return show == true ?
        AlertDialog(
          insetPadding: const EdgeInsets.all(20),
          alignment: Alignment.center,
          title: Container(
            width: double.maxFinite,
            child: Column(
              textDirection: TextDirection.rtl,
              children: [
                Row(
                  textDirection: TextDirection.rtl,
                  children: [
                    const SpinKitCircle(
                      color: Colors.lightBlue,
                      size: 35,
                    ),
                    const SizedBox(width: 20,),
                    Container(
                      alignment: Alignment.center,
                      child: const Text(
                        'please wait',
                        style: TextStyle(
                          color: kGraydark,
                          fontSize: 15,
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        )
        : FutureBuilder(builder: (context, snapshot) {
          Navigator.of(context).pop();
          Navigator.of(context).pop();
          return Container();
        },);
    },);
    

    }

    Navigator.of(context).pop() It must be called twice
    

  2. Try this

    Before ConnectionState.waiting just call this onLoading(context);

    then

    if(ConnectionState. done){
      Navigator.pop();
    }
    
    
    
    void onLoading(BuildContext context) {
        showDialog(
            context: context,
            barrierDismissible: false,
            builder: (BuildContext context) {
              return Center(child:  CircularProgressIndicator(color: Colors.blue));
            });
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search