Home > front end >  State doesn't rebuild after new item is added to list Flutter
State doesn't rebuild after new item is added to list Flutter

Time:05-22

I'm building a Notes app and when I try to add data to the noteslist from another screen it doesn't update the UI in the main screen until I restart the app. Is there a way to track this change and force the app to rebuild that state in flutter.

CodePudding user response:

if you use StatefulWidget you can try add this code at the end of the function that you use to get the data to refresh the state.

setState(() {});

Or even better if you can share the code that you're trying to troubleshoot.

CodePudding user response:

if you want to update state when add item to list, you need to create new list instance, like:

final newList = [...yourList];
final newList.addItem(item);
setState(() {});
  • Related