HomeScreen: Remove unnecessary call to setState
Closed this issue · 2 comments
In Flutter, we should use stateless widgets whenever the state (the data that the screen relies on and displays) changes. In order for our state/data changes to be displayed on that one screen, we must wrap those changes in setState
.
HomeScreen has a call to setState
that doesn't make sense: it is being called in _displayCreateInformationScreen
, which is a function that pushes an entirely new screen onto the navigation stack. There is no state change happening in HomeScreen. Transitioning to one screen from another is not a change in state - it is just transitioning to a new screen, which has its own state. Also, the body of the closure passed to setState
doesn't do anything but generate a new List and ignores the result.
Remove the setState
call from _displayCreateInformationScreen
.
@ybakos I attempted to remove it but it doesn't updated the GridView on the Home/Rhizome page with all the tiles. I had it there initially to trigger a redraw of the grid of tiles.
@ybakos Hmm. I clicked "+", added a new thing, and see the new thingcard shown in the gridview of tiles. Is that the use case you conducted when not seeing the new thingcard appear in the gridview? It "works for me." And it should.. that setState call wasn't doing anything - it only mapped things to cards and discarded the return result... it would have no effect on the data shown in the gridview.
I've gone ahead and removed it. But let me know if I am not understanding/following the right use case (adding a thing and seeing it appear back in the RhizomeScreen.)