Skip to content

Commit e2cd119

Browse files
committed
refactor: Optimize device update logic in GroupViewModel to prevent ValueNotifier-after-dispose errors
1 parent 6b3c2a1 commit e2cd119

1 file changed

Lines changed: 0 additions & 6 deletions

File tree

client/lib/features/devices/view_models/group_view_model.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,10 @@ class GroupViewModel extends BaseViewModel with ViewModelEventBusMixin {
3232
if (existingIndex == -1) {
3333
_devices = [..._devices, device];
3434
} else {
35-
// Replace the existing VM in the list first so the UI can update and
36-
// detach any listeners from the old VM. Dispose the old VM later to
37-
// avoid `ValueNotifier`-after-dispose errors (widgets may still be
38-
// listening during the current frame).
3935
final oldDevice = _devices[existingIndex];
4036
_devices = [..._devices];
4137
_devices[existingIndex] = device;
4238

43-
// Defer disposal to the next microtask/frame so widgets have a chance
44-
// to remove their listeners from the old ValueNotifiers first.
4539
Future.microtask(() {
4640
if (!oldDevice.isDisposed) {
4741
oldDevice.dispose();

0 commit comments

Comments
 (0)