Flutter 当我试图调用一个对话框时,它会显示在生成过程中调用的setState()或markNeedsBuild错误

Flutter 当我试图调用一个对话框时,它会显示在生成过程中调用的setState()或markNeedsBuild错误,flutter,dialog,alert,setstate,bloc,Flutter,Dialog,Alert,Setstate,Bloc,这是我的对话框代码 以下是生成过程中调用的setstate()或markernedsbuild的错误。无法将此覆盖小部件标记为需要处理构建小部件的过程 当我尝试调用_onalertotpwidget时,它会显示此错误。在构建方法中,我已设置bloc并声明注册成功后,我必须调用警报对话框。但当我尝试这样做时,它会向我显示错误。希望你能理解这个问题,请帮助我 _onAlertotp(BuildContext context) { return showDialog<void>

这是我的对话框代码

以下是生成过程中调用的setstate()或markernedsbuild的错误。无法将此覆盖小部件标记为需要处理构建小部件的过程

当我尝试调用_onalertotpwidget时,它会显示此错误。在构建方法中,我已设置bloc并声明注册成功后,我必须调用警报对话框。但当我尝试这样做时,它会向我显示错误。希望你能理解这个问题,请帮助我

  _onAlertotp(BuildContext context) {
    return showDialog<void>(
      context: context,
      barrierDismissible: false, // user must tap button!
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('Enter OTP'),
          content: SingleChildScrollView(
            child: ListBody(
              children: <Widget>[
                Container(
                  height: MediaQuery.of(context).size.height / 2.7,
                  width: MediaQuery.of(context).size.width,
                  alignment: Alignment.center,
                  child: ListView(
                    children: <Widget>[
                      Padding(
                        padding: const EdgeInsets.symmetric(vertical: 8.0),
                        child: Text(
                          'We have Texted and/or Emailed OTP (One Time Pin) to your registered cell phone and/ or email account. Please check and enter OTP below to activate your TUDO account.',
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 15),
                          textAlign: TextAlign.center,
                        ),
                      ),
                      SizedBox(
                        height: 5,
                      ),
                      Padding(
                        padding: const EdgeInsets.symmetric(
                            vertical: 8.0, horizontal: 30),
                        child: PinCodeTextField(
                          length: 6, // must be greater than 0
                          obsecureText: false, //optional, default is false
                          shape: PinCodeFieldShape
                              .underline, //optional, default is underline
                          onDone: (String value) {
                            setState(() {
                              passcode = value;
                              print(value);
                            });
                          },

                          textStyle: TextStyle(
                              fontWeight: FontWeight
                                  .bold), //optinal, default is TextStyle(fontSize: 18, color: Colors.black, fontWeight: FontWeight.bold)
                          onErrorCheck: (bool value) {
                            setState(() {
                              hasError = value;
                            });
                          },
                          shouldTriggerFucntions:
                              changeNotifier.stream.asBroadcastStream(),
                        ),
                      ),
                      Padding(
                        padding: const EdgeInsets.symmetric(horizontal: 30.0),
                        child: Text(
                          hasError
                              ? "*Please fill up all the cells and press VERIFY again"
                              : "",
                          style: TextStyle(
                              color: Colors.red.shade300, fontSize: 12),
                        ),
                      ),
                      SizedBox(
                        height: 20,
                      ),
                      RichText(
                        textAlign: TextAlign.center,
                        text: TextSpan(
                            text: "Didn't receive the code? ",
                            style:
                                TextStyle(color: Colors.black54, fontSize: 15),
                            children: [
                              TextSpan(
                                  text: " RESEND",
                                  // recognizer: onTapRecognizer,
                                  style: TextStyle(
                                      color: colorStyles["primary"],
                                      fontWeight: FontWeight.bold,
                                      fontSize: 16))
                            ]),
                      ),
                      SizedBox(
                        height: 7,
                      ),
                      Container(
                        margin: const EdgeInsets.symmetric(
                            vertical: 16.0, horizontal: 30),
                        child: ButtonTheme(
                          height: 50,
                          child: FlatButton(
                            onPressed: () async {
                              /// check the [_onData] fucntion to understand better
                              changeNotifier.add(Functions.submit);
                              // at first we will check error on the press of the button.
                              if (!hasError) {
                                _onAlertrunnigbusiness(context);
                              }
                            },
                            child: Center(
                                child: Text(
                              "VERIFY".toUpperCase(),
                              style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 18,
                                  fontWeight: FontWeight.bold),
                            )),
                          ),
                        ),
                        decoration: BoxDecoration(
                          color: colorStyles["primary"],
                          borderRadius: BorderRadius.circular(5),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          actions: <Widget>[
            FlatButton(
              child: Text('Regret'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }
\u onAlertotp(构建上下文){
返回显示对话框(
上下文:上下文,
barrierDismissible:false,//用户必须点击按钮!
生成器:(BuildContext上下文){
返回警报对话框(
标题:文本(“输入OTP”),
内容:SingleChildScrollView(
子:列表体(
儿童:[
容器(
高度:MediaQuery.of(context).size.height/2.7,
宽度:MediaQuery.of(context).size.width,
对齐:对齐.center,
子:ListView(
儿童:[
填充物(
填充:常量边集。对称(垂直:8.0),
子:文本(
“我们已向您注册的手机和/或电子邮件帐户发送了文本和/或电子邮件OTP(一次性Pin)。请检查并在下面输入OTP以激活您的TUDO帐户。”,
样式:TextStyle(
fontWeight:fontWeight.bold,fontSize:15),
textAlign:textAlign.center,
),
),
大小盒子(
身高:5,,
),
填充物(
填充:const EdgeInsets.symmetric(
垂直:8.0,水平:30),
子项:PinCodeTextField(
长度:6,//必须大于0
obsecureText:false,//可选,默认值为false
形状:PinCodeFieldShape
.underline,//可选,默认为下划线
onDone:(字符串值){
设置状态(){
密码=值;
印刷品(价值);
});
},
textStyle:textStyle(
fontWeight:fontWeight
.bold),//可选,默认为TextStyle(fontSize:18,颜色:Colors.black,fontWeight:fontWeight.bold)
onErrorCheck:(布尔值){
设置状态(){
hasError=值;
});
},
应触发功能:
changeNotifier.stream.asBroadcastStream(),
),
),
填充物(
填充:常量边集。对称(水平:30.0),
子:文本(
哈斯洛尔
?“*请填写所有单元格,然后再次按验证”
: "",
样式:TextStyle(
颜色:Colors.red.shade300,字体大小:12),
),
),
大小盒子(
身高:20,
),
RichText(
textAlign:textAlign.center,
text:TextSpan(
文本:“没有收到代码?”,
风格:
TextStyle(颜色:Colors.black54,字体大小:15),
儿童:[
TextSpan(
文本:“重新发送”,
//识别器:onTapRecognizer,
样式:TextStyle(
颜色:颜色样式[“主”],
fontWeight:fontWeight.bold,
(尺寸:16)
]),
),
大小盒子(
身高:7,
),
容器(
边距:常量边集。对称(
垂直:16.0,水平:30),
孩子:ButtonTheme(
身高:50,
孩子:扁平按钮(
onPressed:()异步{
///检查[\u onData]功能以更好地理解
changeNotifier.add(Functions.submit);
//首先,我们将检查按下按钮时的错误。
如果(!hasError){
_ONALERTRunnig业务(上下文);
}
},
儿童:中心(
子:文本(
“VERIFY”.toUpperCase(),
样式:TextStyle(
颜色:颜色,白色,
尺码:18,
fontWeight:fontWeight.bold),
)),
),
),
装饰:盒子装饰(
颜色:颜色样式[“主”],
  _onAlertrunnigbusiness(context) {
    return showDialog<void>(
      context: context,
      barrierDismissible: false, // user must tap button!
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('Are you running Business?'),
          content: Container(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                SizedBox(
                  height: 10,
                ),
                Text(
                    "TUDO.App aims at Businesses bridging gaps between Business Service Providers and Consumers collaborate on unique technology platform. If you own a business, we strongly recommend, provide your business information to grow your customer base and expand your business services. Any questions? Call us @1-800-888-TUDO"),
                SizedBox(
                  height: 10,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    FlatButton.icon(
                      icon: Icon(FontAwesomeIcons.arrowCircleRight),
                      label: Text('No'),
                      color: colorStyles["primary"],
                      textColor: Colors.white,
                      padding:
                          EdgeInsets.symmetric(vertical: 10, horizontal: 15),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(7),
                      ),
                      onPressed: () {
                        NavigationHelper.navigatetoMainscreen(context);
                      },
                    ),
                    SizedBox(height: 10),
                    FlatButton.icon(
                      icon: Icon(FontAwesomeIcons.arrowCircleRight),
                      label: Text('Yes'),
                      color: colorStyles["primary"],
                      textColor: Colors.white,
                      padding:
                          EdgeInsets.symmetric(vertical: 10, horizontal: 15),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(7),
                      ),
                      onPressed: () {
                        NavigationHelper.navigatetoBspsignupcreen(context);
                      },
                    ),
                  ],
                )
              ],
            ),
          ),
          actions: <Widget>[
            FlatButton(
              child: Text('Close'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }
  @override
  Widget build(BuildContext context) {
    return BlocListener<SignupBloc, SignupState>(
      bloc: widget._signupBloc,
      listener: (
        BuildContext context,
        SignupState currentState,
      ) {


        if (currentState is InSignupState) {
          _countries = currentState.countries.countries;
          return Container(child: content(_signupBloc, context, _countries));
        }

        if (currentState is SignupButtonClickedEvent) {
          print('SignupButtonClickedEvent clicked');
          return Container();
        }

        if (currentState is SignupSuccessState) {
          print(
              ' You are awesome. you have successfully registered without confirmation');
          print(currentState.signupUser.toJson());
          print("Hey Otp Is opned");

          if (!_isError) {
            return _onAlertotp(context);
          }
          // NavigationHelper.navigatetoMainscreen(context);
          _isLoading = false;
          showAlertBox = true;
          return Container(
            child: content(_signupBloc, context, _countries),
          );
        }

        if (currentState is SignupVerficationOtp) {
          print('signup verficitaion otp button clicked');
          return Container();
        }
        return Container(child: content(_signupBloc, context, _countries));
      },
    );
  }
}
WidgetsBinding.instance.addPostFrameCallback((_) {
  // show alert dialog here
  _onAlertotp(context);
});