简体   繁体   English

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

[英]The method '>' was called on null. Receiver: null Tried calling: >(1e-10) The relevant error-causing widget was Column

I was writing this piece of code:我正在写这段代码:

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'),
              ],
            ),
          ],
        ),

I wanted to make a scrollable grid with a scrollable list under that, but I want to make sure that if I scroll the grid the list isn't scrolled and vice versa.我想制作一个带有可滚动列表的可滚动网格,但我想确保如果我滚动网格,列表不会滚动,反之亦然。 The code above doesn't work.上面的代码不起作用。 Does anyone know why?有谁知道为什么? I'm still a newbie in Flutter and I'm trying to learn it.我仍然是 Flutter 的新手,我正在努力学习它。

just use method to create list of inkWell s and call it as children of the GridView.只需使用方法创建inkWell的列表并将其称为 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;
}

You missed square brackets after for statement.您在 for 语句后错过了square brackets

If you need to recap how to use for in a widget tree take a look here How to use a "for" loop inside children of a widget?如果您需要回顾如何在小部件树中使用for ,请查看此处如何在小部件的子级中使用“for”循环?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 null 上调用了 getter 'length'。 接收方:null 尝试调用:长度。 相关的导致错误的小部件是:/bottom_bar.dart:17:64 - The getter 'length' was called on null. Receiver: null Tried calling: length. The relevant error-causing widget was: /bottom_bar.dart:17:64 在构建 Builder(dirty) 时引发了以下 NoSuchMethodError:在 null 上调用了方法“&gt;=”。 接收器:null 相关的错误原因是: - The following NoSuchMethodError was thrown building Builder(dirty): The method '>=' was called on null. Receiver: null The relevant error-causing was: 错误:在 null 上调用了方法“round”。 接收方:null 尝试调用:round()。 构建小部件时抛出错误 - Error: The method 'round' was called on null. Receiver: null Tried calling: round(). Error thrown when building widget NoSuchMethodError: Class 'bool' 没有实例方法 'call'。 接收者:true 尝试调用:call() 相关的导致错误的小部件是 Home - NoSuchMethodError: Class 'bool' has no instance method 'call'. Receiver: true Tried calling: call() The relevant error-causing widget was Home 在 null 上调用了方法“*”。 接收方:null 尝试调用:*(null) - The method '*' was called on null. Receiver: null Tried calling: *(null) 我该如何解决这个错误? 'NoSuchMethodError' 在 null 上调用了方法 '[]'。 接收器:null。 尝试调用:[]("title") - how can i solve this error? 'NoSuchMethodError' The method '[]' was called on null. Receiver: null. Tried Calling: []("title") FLUTTER MOBX:构建函数返回 null。 相关的导致错误的小部件是观察者 - FLUTTER MOBX: A build function returned null. The relevant error-causing widget was Observer Flutter:方法 &#39;/&#39; 在 null 上被调用。 接收者:空尝试调用:/(1080.0) - Flutter: The method '/' was called on null. Receiver: null Tried calling: /(1080.0) NoSuchMethodError: 在 null 上调用了方法“[]”。 接收者:null 尝试调用:[](&quot;favorites&quot;) - NoSuchMethodError: The method '[]' was called on null. Receiver: null Tried calling: []("favorites") 在 null 上调用了方法“getNotes”。 接收方:null 尝试调用:getNotes - The method 'getNotes' was called on null. Receiver: null Tried calling: getNotes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM