diff --git a/lib/services/shuffleboard_nt_listener.dart b/lib/services/shuffleboard_nt_listener.dart index dfe05b2b..8a8f699c 100644 --- a/lib/services/shuffleboard_nt_listener.dart +++ b/lib/services/shuffleboard_nt_listener.dart @@ -359,7 +359,7 @@ class ShuffleboardNTListener { onWidgetAdded?.call(currentJsonData[jsonKey]!); widget?.unSubscribe(); - widget?.dispose(); + widget?.dispose(deleting: true); }); } @@ -448,7 +448,7 @@ class ShuffleboardNTListener { child['properties']!.putIfAbsent('period', () => Globals.defaultPeriod); widget?.unSubscribe(); - widget?.dispose(); + widget?.dispose(deleting: true); } onWidgetAdded?.call(currentJsonData[jsonKey]!); diff --git a/lib/widgets/dashboard_grid.dart b/lib/widgets/dashboard_grid.dart index 2d6f44f8..c5d0aa15 100644 --- a/lib/widgets/dashboard_grid.dart +++ b/lib/widgets/dashboard_grid.dart @@ -215,6 +215,8 @@ class DashboardGrid extends StatelessWidget { widget.previewRect = widget.draggablePositionRect; widget.previewVisible = false; widget.validLocation = true; + + widget.dispose(); } void onWidgetUpdate(DraggableWidgetContainer widget, Rect newRect) { @@ -282,7 +284,6 @@ class DashboardGrid extends StatelessWidget { _widgetContainers.remove(nt4Container); } } - refresh(); } @@ -447,11 +448,10 @@ class DashboardGrid extends StatelessWidget { } else if (!isValidLocation(previewLocation)) { _containerDraggingIn = null; - if (!fromLayout) { - if (widget.child is NT4Widget) { - (widget.child as NT4Widget) - ..dispose() - ..unSubscribe(); + if (widget.child is NT4Widget) { + widget.child?.dispose(deleting: !fromLayout); + if (!fromLayout) { + widget.child?.unSubscribe(); } } @@ -471,9 +471,7 @@ class DashboardGrid extends StatelessWidget { _containerDraggingIn = null; - if (widget.child is NT4Widget) { - (widget.child as NT4Widget).dispose(); - } + widget.child?.dispose(); refresh(); } @@ -621,7 +619,7 @@ class DashboardGrid extends StatelessWidget { } void removeWidget(DraggableWidgetContainer widget) { - widget.dispose(); + widget.dispose(deleting: true); widget.unSubscribe(); _widgetContainers.remove(widget); refresh(); @@ -629,7 +627,7 @@ class DashboardGrid extends StatelessWidget { void clearWidgets() { for (DraggableWidgetContainer container in _widgetContainers) { - container.dispose(); + container.dispose(deleting: true); container.unSubscribe(); } _widgetContainers.clear(); @@ -638,7 +636,7 @@ class DashboardGrid extends StatelessWidget { void onDestroy() { for (DraggableWidgetContainer container in _widgetContainers) { - container.dispose(); + container.dispose(deleting: true); container.unSubscribe(); } _widgetContainers.clear(); diff --git a/lib/widgets/draggable_containers/draggable_list_layout.dart b/lib/widgets/draggable_containers/draggable_list_layout.dart index 08e8e576..83b7fb42 100644 --- a/lib/widgets/draggable_containers/draggable_list_layout.dart +++ b/lib/widgets/draggable_containers/draggable_list_layout.dart @@ -86,7 +86,7 @@ class DraggableListLayout extends DraggableLayoutContainer { children.remove(container); container.unSubscribe(); - container.dispose(); + container.dispose(deleting: true); refresh(); }); @@ -209,11 +209,11 @@ class DraggableListLayout extends DraggableLayoutContainer { } @override - void dispose() { - super.dispose(); + void dispose({bool deleting = false}) { + super.dispose(deleting: deleting); for (var child in children) { - child.dispose(); + child.dispose(deleting: deleting); } } diff --git a/lib/widgets/draggable_containers/draggable_nt4_widget_container.dart b/lib/widgets/draggable_containers/draggable_nt4_widget_container.dart index ca0ed768..81b39025 100644 --- a/lib/widgets/draggable_containers/draggable_nt4_widget_container.dart +++ b/lib/widgets/draggable_containers/draggable_nt4_widget_container.dart @@ -130,7 +130,7 @@ class DraggableNT4WidgetContainer extends DraggableWidgetContainer { return; } - child!.dispose(); + child!.dispose(deleting: true); child!.unSubscribe(); child = newWidget; @@ -138,10 +138,10 @@ class DraggableNT4WidgetContainer extends DraggableWidgetContainer { } @override - void dispose() { - super.dispose(); + void dispose({bool deleting = false}) { + super.dispose(deleting: deleting); - child?.dispose(); + child?.dispose(deleting: deleting); } @override diff --git a/lib/widgets/draggable_containers/draggable_widget_container.dart b/lib/widgets/draggable_containers/draggable_widget_container.dart index 52b47a92..2bb0ee81 100644 --- a/lib/widgets/draggable_containers/draggable_widget_container.dart +++ b/lib/widgets/draggable_containers/draggable_widget_container.dart @@ -176,7 +176,7 @@ class DraggableWidgetContainer extends StatelessWidget { displayRect = Rect.fromLTWH(x, y, width, height); } - void dispose() {} + void dispose({bool deleting = false}) {} void unSubscribe() {} diff --git a/lib/widgets/nt4_widgets/multi-topic/camera_stream.dart b/lib/widgets/nt4_widgets/multi-topic/camera_stream.dart index 0abf6a9b..09b84c93 100644 --- a/lib/widgets/nt4_widgets/multi-topic/camera_stream.dart +++ b/lib/widgets/nt4_widgets/multi-topic/camera_stream.dart @@ -63,18 +63,20 @@ class CameraStreamWidget extends StatelessWidget with NT4Widget { } @override - void dispose() { + void dispose({bool deleting = false}) { Future(() async { await streamWidget?.cancelSubscription(); httpClient.close(); clientOpen = false; - lastDisplayedImage?.evict(); - streamWidget?.previousImage?.evict(); + if (deleting) { + lastDisplayedImage?.evict(); + streamWidget?.previousImage?.evict(); + } }); - super.dispose(); + super.dispose(deleting: deleting); } @override diff --git a/lib/widgets/nt4_widgets/multi-topic/field_widget.dart b/lib/widgets/nt4_widgets/multi-topic/field_widget.dart index f8ee894d..8a39a855 100644 --- a/lib/widgets/nt4_widgets/multi-topic/field_widget.dart +++ b/lib/widgets/nt4_widgets/multi-topic/field_widget.dart @@ -84,10 +84,12 @@ class FieldWidget extends StatelessWidget with NT4Widget { } @override - void dispose() { - super.dispose(); + void dispose({bool deleting = false}) { + super.dispose(deleting: deleting); - field?.dispose(); + if (deleting) { + field?.dispose(); + } } @override diff --git a/lib/widgets/nt4_widgets/nt4_widget.dart b/lib/widgets/nt4_widgets/nt4_widget.dart index 81742838..abf9d5ba 100644 --- a/lib/widgets/nt4_widgets/nt4_widget.dart +++ b/lib/widgets/nt4_widgets/nt4_widget.dart @@ -93,7 +93,7 @@ mixin NT4Widget on StatelessWidget { nt4Topic ??= nt4Connection.getTopicFromName(topic); } - void dispose() {} + void dispose({bool deleting = false}) {} void unSubscribe() { if (subscription != null) {