首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未显示插入项的动画列表抖动

未显示插入项的动画列表抖动
EN

Stack Overflow用户
提问于 2020-11-08 06:43:42
回答 2查看 271关注 0票数 0

我有一个这样的SliverAnimatedList:

代码语言:javascript
复制
 SliverAnimatedList(
                  key: _myListkey,
                  itemBuilder: (context, index, animation) {
                    return Container(
                      child: Column(
                        children: [
                          FlashcardCreateTile(
                            autocreate: autocreate,
                            entertomovefocus: entertomovefocus,
                            flashcard: flashcards[index],
                            islast:
                                (index + 1) == flashcards.length ? true : false,
                            plusmode: true,
                            promode: true,
                            uid: widget.uid,
                            focus: null,
                            animation: animation,
                            formKey: _formkey,
                            delete: () {
                              flashcards.removeAt(index);
                              SliverAnimatedList.of(context).removeItem(
                                  index,
                                  (context, animation) => FlashcardCreateTile(
                                      autocreate: autocreate,
                                      entertomovefocus: entertomovefocus,
                                      flashcard:
                                          Flashcard(recto: "", verso: ""),
                                      islast: false,
                                      plusmode: true,
                                      promode: true,
                                      uid: widget.uid,
                                      focus: null,
                                      animation: animation,
                                      formKey: _formkey,
                                      delete: () {},
                                      add: () {}),
                                  duration: const Duration(milliseconds: 100));
                            },
                            add: () {
                              int insertitem = index + 1;
                              print(insertitem);
                              setState(() {
                                flashcards.insert(
                                    insertitem,
                                    Flashcard(
                                        recto: "",
                                        verso: "",
                                        mode: 0,
                                        isrelearning: false,
                                        easefactor: widget
                                            .folder
                                            .decklist[widget.deckindex]
                                            .startingEase,
                                        currentInterval:
                                            Duration(microseconds: 0),
                                        previousInterval:
                                            Duration(microseconds: 0)));
                                SliverAnimatedList.of(context)
                                    .insertItem(insertitem);
                                SliverAnimatedList.of(context).build(context);
                              });
                            },
                          ),
                          Container(
                            child: (index + 1) == flashcards.length
                                ? Container(
                                    child: SizedBox(
                                      height: 50,
                                    ),
                                  )
                                : Container(),
                          )
                        ],
                      ),
                    );
                  },
                  initialItemCount: flashcards.length,
                )

当我单击和一个按钮时,flashcardcreatetile将返回add函数:

代码语言:javascript
复制
IconButton(
                  icon: Icon(
                    Icons.add,
                    color: Colors.red,
                  ),
                  onPressed: widget.add)

下面是它正在做的事情:

正如您所看到的,该项目确实已插入,但只有当我向下滚动和向上滚动时,sliveranimatedlist才会显示它,因此我认为它需要重新构建自身。

我想让新卡直接显示出来,有什么想法吗?顺便说一句,删除项目工作正常

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-11-08 08:20:18

您需要向项目列表中添加一个键。我建议您阅读this article,因为您将了解为什么需要密钥,它们有什么好处,以及如何解决您的问题。

票数 1
EN

Stack Overflow用户

发布于 2020-11-08 06:49:47

您应该向FlashcardCreateTile项目添加一个key: Key(index),以使其具有唯一性。

Flutter引擎需要它来正确地建立你的列表

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64733137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档