0

I have been creating an app with a start(homescreen) that display a list of data extracted from a REST api call. This is triggered to be done when the state of the widget updates - all works fine.

I also have a number of child screens (for instance a settings screen) loaded with:

Navigator.push

I have noticed that if the state changes in my settings screen that the homescreen state is also updated and therefore it calls the REST api again. I have done some testing and this appears to work for any child widget in the Navigator stack where state update appears to be passed back up the widget tree right to the top.

Is this expected behaviour as I thought that state changes went down the widget tree not back up or is this my misunderstanding of the way this works?

It just seems a bit inefficient to me that my REST call in the HomeScreen keeps getting executed and the screen updating every-time a child widget has a state change as it is the base of the Navigator stack and not being used/viewed.

I have put up a simple test project that shows this on Github here.

  • Flutter (Channel beta, v0.11.3, on Mac OS X 10.14.1 18B75, locale en-GB)
  • Android toolchain - develop for Android devices (Android SDK 28.0.3)
  • iOS toolchain - develop for iOS devices (Xcode 10.1)
  • Android Studio (version 3.1)
  • VS Code (version 1.29.1)
Steve
  • 557
  • 5
  • 17
  • In your example, what happens if you change `HomeScreen` to a `StatelessWidget`? I know in your real code it probably has to be `StatefulWidget` but in your example it can be a `StatelessWidget`. – dragonfly02 Nov 17 '18 at 16:56
  • see https://stackoverflow.com/questions/52249578/how-to-deal-with-unwanted-widget-build – Rémi Rousselet Nov 17 '18 at 17:03
  • @stt106 the example was just to be as simple as possible, but in my app the HomeScreen needs to be a Stateful widget, looks like I need to re-think some of my architecture. – Steve Nov 17 '18 at 17:16

0 Answers0