From 6bd42a9d75c23c256d0e22b71cdb28f3348469d8 Mon Sep 17 00:00:00 2001 From: Andy Horn Date: Tue, 24 Dec 2024 19:06:32 -0700 Subject: [PATCH 1/2] fix: controller notifying during build --- lib/src/resizable_container.dart | 2 +- lib/src/resizable_controller.dart | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/src/resizable_container.dart b/lib/src/resizable_container.dart index 48cd1bd..b19a618 100644 --- a/lib/src/resizable_container.dart +++ b/lib/src/resizable_container.dart @@ -46,7 +46,7 @@ class _ResizableContainerState extends State { void initState() { super.initState(); - controller.setChildren(widget.children); + manager.initChildren(widget.children); } @override diff --git a/lib/src/resizable_controller.dart b/lib/src/resizable_controller.dart index 1767740..6c9a641 100644 --- a/lib/src/resizable_controller.dart +++ b/lib/src/resizable_controller.dart @@ -71,11 +71,22 @@ class ResizableController with ChangeNotifier { } void setChildren(List children) { + _setChildren(children, true); + } + + void _initChildren(List children) { + _setChildren(children, false); + } + + void _setChildren(List children, bool notify) { _children = children; _sizes = children.map((child) => child.size).toList(); _pixels = List.filled(children.length, 0); _needsLayout = true; - notifyListeners(); + + if (notify) { + notifyListeners(); + } } void _setRenderedSizes(List pixels) { @@ -328,6 +339,10 @@ final class ResizableControllerManager { void setNeedsLayout() { _controller._needsLayout = true; } + + void initChildren(List children) { + _controller._initChildren(children); + } } abstract class ResizableControllerTestHelper { From 2efd21d22b5c3e9de854bbec1fd3c786b40c845c Mon Sep 17 00:00:00 2001 From: Andy Horn Date: Tue, 24 Dec 2024 19:13:52 -0700 Subject: [PATCH 2/2] Use named argument for notify --- lib/src/resizable_controller.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/resizable_controller.dart b/lib/src/resizable_controller.dart index 6c9a641..c6be275 100644 --- a/lib/src/resizable_controller.dart +++ b/lib/src/resizable_controller.dart @@ -71,14 +71,14 @@ class ResizableController with ChangeNotifier { } void setChildren(List children) { - _setChildren(children, true); + _setChildren(children, notify: true); } void _initChildren(List children) { - _setChildren(children, false); + _setChildren(children, notify: false); } - void _setChildren(List children, bool notify) { + void _setChildren(List children, {required bool notify}) { _children = children; _sizes = children.map((child) => child.size).toList(); _pixels = List.filled(children.length, 0);