【发布时间】:2021-02-20 06:43:27
【问题描述】:
我有一个像这样的 SliverAnimatedList:
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 会发回添加功能:
IconButton(
icon: Icon(
Icons.add,
color: Colors.red,
),
onPressed: widget.add)
如您所见,该项目确实已插入,但 sliveranimatedlist 仅在我向下滚动和向上滚动时显示它,所以我认为它需要重建自身..
我想直接显示新卡,有什么想法吗?顺便说一句,删除项目工作正常
【问题讨论】:
标签: flutter flutter-layout flutter-animation