Flutter - refresh single element in ListView on ListTile tap

Viewed 679

Here is flow I want to achieve:

  • get list of items and put it in ListView as ListTile
  • on item tap update item status in Firebase (from unread to read)
  • refresh single one item in List
  • navigate to other
  • on click back button get list with updated element - marked as readed

Is there any possibility to refresh single one element in ListView on tap? By now I tried to use setState() method but It didn't work - item is updated in Firebase but change doesn't appears in list until I refresh page manually.

onTap function

onTap: () {
  setState(() {
    _notifications[index].data['viewed'] = true;
  });

  _userService.setNotificationAsClicked(_notifications[index].data['id']);
  Navigator.of(context).pushNamed(_notifications[index].data['routing']);
},

BackButton:

return Container(
  child: BackButton(
    onPressed: () {
      Navigator.pop(context);
    },
  ),
);

EDIT: It works when in back button I use Navigator.of(context).pushNamed(...) instead of Navigator.pop(), but in this case I need to scroll down and reload again all elements...

I FOUND SOLUTION!!!

All I need to do was change storing List with DocumentSnapshot to List with data from DocumentSnapshot.

0 Answers
Related