【问题标题】:AlertBox is not showing flutterAlertBox 未显示抖动
【发布时间】:2020-08-29 14:48:52
【问题描述】:

我有带有图像和一些细节的 Listview,如果没有数据,它应该返回一个带有消息的警报框,但是当我尝试时,警报框没有出现,我为此使用 rflutter

如果没有数据,我会得到什么

{
  "status": true,
  "Image": []
}

如果json返回没有数据,应该弹出警告框

图片列表代码

 Future<String> getImageList(String set_id) async {

        ProgressDialog dialog = CustomDialogs().showLoadingProgressDialog(context);

             var response = await http.post(Urls.ImageList,
                  headers: {
                    "Content-Type": "application/json",
                    "Authorization": "Bearer $token",
                  },
                  body: json.encode({
                    "sets_id": set_id,

                  }));

              if (response.statusCode == 200) {

                dialog.dismissProgressDialog(context);

                try {
                  var resp = response.body;
                  print(resp);
                  if(resp != null)
                    {
                      Map<String, dynamic> value = json.decode(resp);
                      var report = value['Image'];

                      for (int i = 0; i < report.length; i++) {
                        var data = report[i];
                        var SetName = data["Set_Id"]["Set_Name"];

                        Imagelist.add(ImageModel.fromJson(data, SetName , ));
                      }

                      setState(() {
                        array_lenth = Imagelist.length;
                      });
                    }
                  else
                    {
                      Alert(
                        context: context,
                        type: AlertType.error,
                        title: "No Data",
                        desc: "No Avilable Data Found",
                        buttons: [
                          DialogButton(
                            child: Text(
                              "COOL",
                              style: TextStyle(color: Colors.white, fontSize: 20),
                            ),
                            onPressed: () => Navigator.pop(context),
                            width: 120,
                          )
                        ],
                      ).show();
                    }

                } catch (e) {
                  e.toString();
                }
              }
              else {
                print("Error");
              }
          }
      }

【问题讨论】:

    标签: flutter flutter-layout flutter-dependencies


    【解决方案1】:

    您正在检查 null,但您应该检查长度。

    你的条件应该如下。

     if(resp.length < 0)
    

    【讨论】:

    • 不,它不起作用,警报不会出现@Viren V Varasadiya
    • 立即尝试。 @abhijith
    • 我尝试使用小于号 if(resp.length
    • 我更新了我的答案。如果它帮助你接受我的回答。 @abhijith
    猜你喜欢
    • 1970-01-01
    • 2020-10-04
    • 2012-07-20
    • 1970-01-01
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多