颤动动态复选框不会改变

时间:2018-03-07 20:53:47

标签: flutter

我正在动态构建一个CheckboxListTile,它很好但是当我单击复选框时我会收到此错误

The following assertion was thrown building NotificationListener<KeepAliveNotification>:
'package:flutter/src/rendering/object.dart': Failed assertion: line 2730 pos 14:
'_debugUltimatePreviousSiblingOf(after, equals: _firstChild)': is not true.

似乎与重复键有关,所以我在我的顶级列表视图中添加了一个键并且错误已停止,但现在

我的复选框列表使用此代码构建

new FutureBuilder(
            future: _getRefDocs(),
            builder: (BuildContext context, AsyncSnapshot<List> snapshot) {
              switch (snapshot.connectionState) {
                case ConnectionState.none:
                  return new Text('Waiting to start');
                case ConnectionState.waiting:
                  return new Text('');
                default:
                  if (snapshot.hasError) {
                    return new Text('Error: ${snapshot.error}');
                  } else {
                    //myInitialData = snapshot.data;
                    return new ListView(
                      key: new Key(key['docid'].toString())
                      children: snapshot.data.map((dynamic key) {
                        bool myvalue = false;
                        if (key['selected'] == 1) {
                          myvalue = true;
                          selectdocs.add(key['docid']);
                        }
                        return new CheckboxListTile(
                            title: new Text(key['docname']),
                            value: myvalue,
                            //selected: myvalue,
                            onChanged: (bool value) {
                              setState(() {
                                myvalue = value;
                              });

                              if (value == true) {
                                selectdocs.add(key['docid']);
                              } else {
                                selectdocs.remove(key['docid']);
                              }
                            }
                        );
                      }).toList(),
                    );
                  }
              }
            });

现在我添加了键后,键盘不会弹出,单击时复选框不会改变,当我点击它时,它会弹回到顶部的文本框焦点。如果我删除密钥,则每次单击复选框时都会返回错误。

有什么想法吗?

0 个答案:

没有答案