flutter 诊断属性< BoxConstraints>

jm81lzqq  于 2023-03-04  发布在  Flutter
关注(0)|答案(2)|浏览(133)

请我有这个错误在我的Flutter代码.下面是我的代码:
返回脚手架(

appBar: AppBar(

      backgroundColor: Colors.black,
      leading: IconButton(
          onPressed: () {
            Navigator.of(context).pop();
          },
          icon: const Icon(Icons.arrow_back_ios)),
      title: const Text('Categories'),
    ),
    body: Container(
      color: Colors.black,
      height: double.infinity,
      width: double.infinity,
      transformAlignment: Alignment.center,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          SizedBox(
            child: ListView(
              shrinkWrap: true,
              physics: const BouncingScrollPhysics(),
              children: [
                ListTile(
                  title: const Text(
                    "Option1",
                    style: TextStyle(color: Colors.white),
                  ),
                  onTap: () {},
                ),
                Container(height: 2, color: Colors.white),
                ListTile(
                  title: const Text(
                    "Option2",
                    style: TextStyle(color: Colors.white),
                  ),
                  onTap: () {},
                ),
                Container(height: 2, color: Colors.white),
                ListTile(
                  title: const Text(
                    "Option3",
                    style: TextStyle(color: Colors.white),
                  ),
                  onTap: () {},
                ),
                Container(height: 2, color: Colors.white),
                ListTile(
                  title: const Text(
                    "Option4",
                    style: TextStyle(color: Colors.white),
                  ),
                  onTap: () {},
                ),
              ],
            ),
          ),
          Container(
            color: Colors.white,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Row(
                  children: [
                    GestureDetector(
                      onTap: () {
                        showDialog(
                            context: context,
                            builder: (context) => AlertDialog(
                                  title: const Text('pick color'),
                                  content: SingleChildScrollView(
                                      child: ColorPicker(
                                    pickerColor: pickerColor,
                                    onColorChanged: changeColor,
                                  )),
                                  actions: [
                                    ElevatedButton(
                                      child: const Text("You gerrit now"),
                                      onPressed: () {
                                        setState(() =>
                                            currentColor = pickerColor);
                                        Navigator.of(context).pop();
                                      },
                                    )
                                  ],
                                ));
                      },
                    ),
                    const Text(
                      "colorpicker",
                    ),
                    const Text("stuff",
                        style: TextStyle(
                            color: Colors.white,
                            backgroundColor: Colors.green)),
                  ],
                ),
              ],
            ),
          )
        ],
      ),
    ));

此外,下面是我的调试控制台中指向代码缺陷点的错误:
if(!约束.有界高度){

RenderBox node = this;
      while (
          !node.constraints.hasBoundedHeight && node.parent is RenderBox) {
        node = node.parent! as RenderBox;
      }

      information.add(node.describeForError(
          'The nearest ancestor providing an unbounded height constraint is'));
    }
    throw FlutterError.fromParts(<DiagnosticsNode>[
      ...information,
      DiagnosticsProperty<BoxConstraints>(
          'The constraints that applied to the $runtimeType were',
          constraints,
          style: DiagnosticsTreeStyle.errorProperty),
      DiagnosticsProperty<Size>('The exact size it was given was', _size,
          style: DiagnosticsTreeStyle.errorProperty),
      ErrorHint(
          'See https://flutter.dev/docs/development/ui/layout/box-constraints for more information.'),
    ]);
  }

我认为这是来自列表视图,我尝试了所有可能的编辑,即使是在线资源,我仍然以相同的错误结束。我将容器(最初包裹在列表视图周围)更改为sizedBox,我还将shrinkwrap设置为true,并添加了物理键和值,但没有任何改善

1aaf6o9v

1aaf6o9v1#

您可以为ListTile设置sizebox的高度:

height: MediaQuery.of(context).size.height * 0.2,
g9icjywg

g9icjywg2#

你需要在GestureDetector上提供child。另外,你可以做一些调整,比如使用scaffold backgroundColor
这是一个简单的结构

Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.black,
          leading: IconButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              icon: const Icon(Icons.arrow_back_ios)),
          title: const Text('Categories'),
        ),
        backgroundColor: Colors.black,
        body: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Expanded(
              child: ListView(
                physics: const BouncingScrollPhysics(),
                children: [
                  ListTile(
                    title: const Text(
                      "Option1",
                      style: TextStyle(color: Colors.white),
                    ),
                    onTap: () {},
                  ),
                  Container(height: 2, color: Colors.white),
                  ListTile(
                    title: const Text(
                      "Option2",
                      style: TextStyle(color: Colors.white),
                    ),
                    onTap: () {},
                  ),
                  Container(height: 2, color: Colors.white),
                  ListTile(
                    title: const Text(
                      "Option3",
                      style: TextStyle(color: Colors.white),
                    ),
                    onTap: () {},
                  ),
                  Container(height: 2, color: Colors.white),
                  ListTile(
                    title: const Text(
                      "Option4",
                      style: TextStyle(color: Colors.white),
                    ),
                    onTap: () {},
                  ),
                ],
              ),
            ),
            Container(
              color: Colors.white,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  GestureDetector(
                    onTap: () {},
                    child: const Text(
                      "colorpicker",
                    ),
                  ),
                  const Text("stuff",
                      style: TextStyle(
                          color: Colors.white, backgroundColor: Colors.green)),
                ],
              ),
            )
          ],
        ));
  }

相关问题