ParentDataWidget 的不正确使用(无堆栈跟踪)

Incorrect use of ParentDataWidget (No stacktrace)

我有以下警报对话框布局:

AlertDialog(
        title: Text('Some Text'),
        content: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
          return Container(
              height: MediaQuery.of(context).size.height,
              width: MediaQuery.of(context).size.width,
              child: ListView(
                children: [
                    ListView.builder(
                    shrinkWrap: true,
                    physics: NeverScrollableScrollPhysics(),
                    itemCount: usersWithoutBirthdays.length,
                    itemBuilder: (BuildContext context, int index) {
                      return CheckboxListTile(
                          title: Text("More Text Here"),
                          value: someValue,
                          onChanged: (bool? value) {
                            if (value != null) {
                              setState(() {
                                //Set state logic here
                              });
                            }
                          }
                        );
                      },
                    ),
                    Spacer(),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        TextButton(
                          child: Text("Cancel"),
                          onPressed: () {
                            Navigator.pop(context);
                          },
                        ),
                        TextButton(
                            child: Text("Continue"),
                            onPressed:
                            //OnPressed logic here
                        ),
                      ],
                    )
                ],
              )
            );
          }
        )
    );

在控制台中我看到的是:

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ Incorrect use of ParentDataWidget.

每当我在显示的警报中向下滚动时,都会发生这种情况。

我看过类似的问题 (here, ) 并尝试了以下解决方案:

如您所见,ListView 的布局中没有扩展小部件,并且由于堆栈跟踪没有提供信息,我不明白问题出在哪里。

我是否应该以不同的方式布置警报对话框?我要完成的是有一个可滚动的布局,并有一个用户可以标记的复选框列表。

忽略此错误,所有功能正常,没有其他问题。

从您的代码中删除 Spacer Widget。试试下面的代码希望对你有帮助。

用于测试的布尔变量 checked and unchecked CheckBox

  bool someValue = false;

您的小部件:

  ElevatedButton(
        onPressed: () {
          // write your onPressed function here
          alertDialog();
          print('Button Pressed');
        },
        child: const Text('Press Me'),
      ),

您的 alertDialog 方法:

alertDialog() {
    showDialog(
      context: context,
      builder: (context) {
        return AlertDialog(
          title: Text('Some Text'),
          content: StatefulBuilder(
            builder: (BuildContext context, StateSetter setState) {
              return Container(
                height: MediaQuery.of(context).size.height,
                width: MediaQuery.of(context).size.width,
                child: ListView(
                  children: [
                    ListView.builder(
                      shrinkWrap: true,
                      physics: NeverScrollableScrollPhysics(),
                      itemCount: 30,//usersWithoutBirthdays.length,
                      itemBuilder: (BuildContext context, int index) {
                        return CheckboxListTile(
                            title: Text("More Text Here"),
                            value: someValue,
                            onChanged: (bool value) {
                              if (value != null) {
                                setState(() {
                                  //Set state logic here
                                });
                              }
                            });
                      },
                    ),
                  ],
                ),
              );
            },
          ),
          actions: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                TextButton(
                  child: Text("Cancel"),
                  onPressed: () {
                    Navigator.pop(context);
                  },
                ),
                TextButton(
                  child: Text("Continue"),
                  onPressed: () {},
                  //OnPressed logic here
                ),
              ],
            ),
          ],
        );
      },
    );
  }

您可以测试您的代码Dartpad