Reputation: 1574
Root widget of the app route
@override
Widget build(BuildContext context) {
return SafeArea(
child: MyStatefulWidget(),
);
}
In the inner stateful widget I have text field with focus management. FocusNode disposed in dispose() callback. And finally - if keyboard is opened - all screen rebuilts, and my stateful widget also fully rebuilts with state. Dispose called and keyboard dissapears because of focus node disposed.
My conclusion - all controllers must be provided from route's root widget, because only root widget lives all time without recreate. This is very strange and inconvenient - I can't has self managed widgets and must provide all controlles from outside? If it is true, then how animations, text fields and other widget works? This is mean every rebuild cause state recreation and all animations, etc will stop on rebuild?.. Or there is way to save state between widget recreation? Save state and restore (like android parcelable) between recreation?
Upvotes: 0
Views: 1383
Reputation: 1574
I found my problem: Scaffold has GlobalKey which created in StatefulWidget instead State. And all tree with states was recreated on every rebuild:)
Upvotes: 1
Reputation: 101
Please try, use AutomaticKeepAliveClientMixin
mixin, this mixin rebuild from old widget.
Detail visit: https://medium.com/@diegoveloper/flutter-persistent-tab-bars-a26220d322bc
Upvotes: 2