insertOrUpdatePost method
Inserts a new post on top or updates an existing post.
Logic
- find existing post and replace. Or add new one on top.
- render the view
- scroll to the post
Implementation
insertOrUpdatePost(ApiPost post) {
postInEdit = null;
int i = posts.indexWhere((p) => p!.idx == post.idx);
int jumpTo = 0;
if (i == -1) {
posts.insert(0, post);
} else {
posts[i] = post;
jumpTo = i;
}
render!();
if (listController.isAttached)
WidgetsBinding.instance!.addPostFrameCallback((x) {
listController.jumpTo(index: jumpTo);
});
}