mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-26 16:46:51 +08:00
JournalList: Do not show a removal animation if dismissed
Otherwise we show an animation twice, and it is quite jarring.
This commit is contained in:
@ -29,6 +29,7 @@ class JournalList extends StatefulWidget {
|
||||
|
||||
class _JournalListState extends State<JournalList> {
|
||||
var _listKey = GlobalKey<AnimatedListState>();
|
||||
var deletedViaDismissed = <String>[];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -57,14 +58,19 @@ class _JournalListState extends State<JournalList> {
|
||||
_listKey.currentState.insertItem(index);
|
||||
}
|
||||
|
||||
void _noteRemoved(int index, Note _) {
|
||||
void _noteRemoved(int index, Note note) {
|
||||
if (_listKey.currentState == null) {
|
||||
return;
|
||||
}
|
||||
_listKey.currentState.removeItem(
|
||||
index,
|
||||
(context, animation) => _buildItem(context, 0, animation),
|
||||
);
|
||||
_listKey.currentState.removeItem(index, (context, animation) {
|
||||
var i = deletedViaDismissed.indexWhere((path) => path == note.filePath);
|
||||
if (i == -1) {
|
||||
return _buildItem(context, 0, animation);
|
||||
} else {
|
||||
deletedViaDismissed.removeAt(i);
|
||||
return Container();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@ -112,6 +118,8 @@ class _JournalListState extends State<JournalList> {
|
||||
backgroundColor: Colors.red[800],
|
||||
iconData: Icons.delete,
|
||||
onDismissed: (direction) {
|
||||
deletedViaDismissed.add(note.filePath);
|
||||
|
||||
final stateContainer = StateContainer.of(context);
|
||||
stateContainer.removeNote(note);
|
||||
|
||||
|
Reference in New Issue
Block a user