Once you start a match or open any other page in the app, the parent page is also rebuilt in the backgroud multiple times. If we navigate to the friends tab and back to play tab, then all tabs on the way get rebuilt too. This is awful because it refetches data (specially the main tab match stream is reset, but also the who is online checker for the friends tab), which is slow for low connectivy and costs us lots of DB reads. Plus the app glitches and there are hiccups when activating the keyboard.
2 culprits:
Solutions:
MediaQuery.of(context).size
: when the keyboard goes up, it changes this object and the whole widget rebuilds unnecessarily https://github.com/flutter/flutter/issues/72988#issuecomment-751511716Navigator.of(context).pushPageRouteBuilder(opaque: false, pageBuilder: (BuildContext context, _, __)
instead of Navigator.of(context).pushReplacement(new MaterialPageRoute(builder: (BuildContext context)
: The second option mutates the route tree object and causes the whole tree to re-render. Attention, the `opaque: false`` option causes the screen to be an overlay, and may be computationally heavy? We need to pay attention to how this will play out in the future, but considering our app does not have lots of intense UI objects or animations, it should be fine. Slow connectivity is likely to affect users more than slow phone computation. https://github.com/flutter/flutter/issues/11655#issuecomment-552101522More links:
https://github.com/flutter/flutter/pull/41763
https://stackoverflow.com/questions/52249578/how-to-deal-with-unwanted-widget-build
https://github.com/flutter/flutter/issues/11655#issuecomment-552818136
https://medium.com/saugo360/flutter-my-futurebuilder-keeps-firing-6e774830bc2