Default GroupButtonController must be created in _GroupButtonBodyState
slavap opened this issue · 0 comments
slavap commented
The following code is wrong, because it leads to default GroupButtonController rebuild on every GroupButton.build(), so I have to always pass external GroupButtonController to GroupButton constructor.
return GroupButtonBody(
...
controller: controller ?? GroupButtonController(),
);
The right code should be like this:
class _GroupButtonBodyState extends State<GroupButtonBody> {
GroupButtonController _controller = widget.controller ?? GroupButtonController();
@override
void didUpdateWidget(covariant GroupButtonBody oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.controller != widget.controller) _controller = widget.controller ?? GroupButtonController();
}