Hello,
Thank you for sharing your book, I am one of those which got a free copy.
In your examples with StatefulWidgets, when you override initState() you call super.initState() at the end of the block which is wrong. It’s wrong both from the documentation and from my experience.
As a rule of thumb:
- super.initState() should be called first;
- super.dispose() should be called last;
This way, we are sure the state is initalised (and the context is ready) before we use it and disposed after we clean up the code.
Seeing how this is a book which teaches, mostly, beginners it’s important what you teach.
You can read from documentation: initState method - State class - widgets library - Dart API
“Implementations of this method should start with a call to the inherited method, as in super.initState().”