Search code examples
flutterflutter-navigation

Flutter Widgets lifecycle (Navigation)


How is a Widget's lifecycle affected by navigation changes? When is a Widget destroyed, rebuilt, etc. regarding both Stateless and Statefull Widget? All information I found is about Statefull Widget's lifecycle, but nothing relating it to navigation and Stateless Widget's rebuilds.


Solution

    1. Widget does not get rebuilt with Navigation. They are still there in widget tree. They simply aren't visible (as pages are in navigation stack). You can verify this by viewing Widget Tree from dart-tool.

    2. Stateless widgets are built only once per declaration if their constructor is const and params doesn't change in parent while calling them.