首页 > 解决方案 > 在 null 上调用了方法“>”。Receiver: null 尝试调用:>(1e-10) 相关的导致错误的小部件是 Column

问题描述

我正在写这段代码:

Column(
          children: <Widget>[
            GridView.count(
              crossAxisSpacing: 10,
              mainAxisSpacing: 1,
              crossAxisCount: 7,
              children: <Widget>[
                for (int c = 0; c < 10 /*0000*/; c++)
                  InkWell(
                    child: Container(
                      padding: EdgeInsets.all(8),
                      decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        color: dateColors[c],
                      ),
                      child: setDay(c),
                    ),
                    onTap: () {
                      setState(() {
                        changeColors(c);
                      });
                    },
                  ),
              ],
            ),
            ListView(
              shrinkWrap: true,
              children: <Widget>[
                Text("I'm dedicating every day to you"),
                Text('Domestic life was never quite my style'),
                Text('When you smile, you knock me out, I fall apart'),
                Text('And I thought I was so smart'),
              ],
            ),
          ],
        ),

我想制作一个带有可滚动列表的可滚动网格,但我想确保如果我滚动网格,列表不会滚动,反之亦然。上面的代码不起作用。有谁知道为什么?我仍然是 Flutter 的新手,我正在努力学习它。

标签: flutterdart

解决方案


只需使用方法创建inkWells 列表并将其称为 GridView 的子项。

Column(
      children: <Widget>[
        GridView.count(
          crossAxisSpacing: 10,
          mainAxisSpacing: 1,
          crossAxisCount: 7,
          children: _createInkWellWidgets(),
        ),
        ListView(
          shrinkWrap: true,
          children: <Widget>[
            Text("I'm dedicating every day to you"),
            Text('Domestic life was never quite my style'),
            Text('When you smile, you knock me out, I fall apart'),
            Text('And I thought I was so smart'),
          ],
        ),
      ],
    )

List<Widget> _createInkWellWidgets() {
  List<Widget> widgets = [];
  for (int c = 0; c < 10; c++) {
    widgets.add(InkWell(
      child: Container(
        padding: EdgeInsets.all(8),
        decoration: BoxDecoration(
          shape: BoxShape.circle,
          color: dateColors[c],
        ),
        child: setDay(c),
      ),
      onTap: () {
        setState(() {
          changeColors(c);
        });
      },
    ));
  }
  return widgets;
}

推荐阅读