The main page has many children widgets. When searching, SearchWidget
is shown, otherwise DashletsWidget
is shown.
DashletsWidget
has TabController
. TabController
is kept in the main page, so that active tab is not reset after searching.
DashletsWidget
has a dashlet setting pane, which might change number of tabs.
DashletsWidget(ValueNotifier<int> dashletCount, TabController controller)
use ValueNotifier
to let re-create controller
to the parent: . While re-creating, the old TabController cannot be disposed reliably, so let just de-reference without disposing. It is kind-of-work, but so un-natural. Is there a good pattern to update TabController.length
.
It's fine to let your unused TabController
be garbage collected.
Here's another strategy that might feel better: You could have store the information about the number of tabs in a model object that is owned in a State
at a higher level of your tree than DashletsWidget
, and pass that model object as configuration values to DashletsWidget
. If the DashletsWidget
is rebuilt and the constructor arguments change, the didUpdateWidget
method of DashletsWidgetState
will be called and you can use that as an opportunity to replace the TabController
. Or alternatively you could use the number of tabs to construct a ValueKey
for DashletsWidget
and so changing tabs configuration would automatically dispose
the existing DashletsWidgetState
and replace it with a fresh one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With