Chapter 5 Creating the Future inside FutureBuilder

Just a quick observation… while working through Chapter 5, I noticed the examples create new work inside of the FutureBuilder.

The book recommends reading up on FutureBuilder, which I did. I then found the official Flutter docs specifically recommend against creating the future inside a FutureBuilder. The reason being that a widget can be rebuilt unexpectedly and quite often. For example, switching from Dark to Light mode could cause a rebuild… or simply switching back and forth between tabs several times quickly spawns multiple mock service threads. Adding some debugLog() calls to the mock service shows indeed there can be multiple mock service threads as a result.

Wouldn’t it make more sense to create and hold the future outside of the FutureBuilder, then reference that future instead? That way, if the future work already exists and is complete, no new work needs to happen.

I’m not sure exactly how that should be structured in the code, though.