flutter - Pattern for updating TabController length from child widget -
the main page has many children widgets. when searching, searchwidget shown, otherwise dashletswidget shown.
dashletswidget has tabcontroller. tabcontroller kept in main page, active tab not reset after searching.
dashletswidget has dashlet setting pane, might change number of tabs.
dashletswidget(valuenotifier<int> dashletcount, tabcontroller controller) use valuenotifier let re-create controller parent: . while re-creating, old tabcontroller cannot disposed reliably, let de-reference without disposing. kind-of-work, un-natural. there pattern update tabcontroller.length.
it's fine let unused tabcontroller garbage collected.
here's strategy might feel better: have store information number of tabs in model object owned in state @ higher level of tree dashletswidget, , pass model object configuration values dashletswidget. if dashletswidget rebuilt , constructor arguments change, didupdatewidget method of dashletswidgetstate called , can use opportunity replace tabcontroller. or alternatively use number of tabs construct valuekey dashletswidget , changing tabs configuration automatically dispose existing dashletswidgetstate , replace fresh one.
Comments
Post a Comment