-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flutter: disconnect connections when disposing group
- Loading branch information
Showing
2 changed files
with
35 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
This file is part of KDDockWidgets. | ||
SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
Author: Sérgio Martins <[email protected]> | ||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only | ||
Contact KDAB at <[email protected]> for commercial licensing options. | ||
*/ | ||
|
||
import 'package:signals_slots/signals_slots.dart'; | ||
|
||
mixin HasConnections { | ||
final List<Connection> connections = []; | ||
void connect(var signal, action) { | ||
connections.add(signal.connect(action)); | ||
} | ||
|
||
void disconnect() { | ||
for (var con in connections) con.disconnect(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,15 @@ | |
Contact KDAB at <[email protected]> for commercial licensing options. | ||
*/ | ||
|
||
import 'package:KDDockWidgets/HasConnections.dart'; | ||
import 'package:KDDockWidgets/KDDockWidgets.dart'; | ||
import 'package:KDDockWidgets/widgets/PositionedWidget.dart'; | ||
import 'package:KDDockWidgets/widgets/TabBarWidget.dart'; | ||
import 'package:KDDockWidgets/widgets/TitleBarWidget.dart'; | ||
import 'package:KDDockWidgets/widgets/DockWidget.dart'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:signals_slots/signals_slots.dart'; | ||
|
||
class GroupWidget extends PositionedWidget { | ||
final Group group; | ||
|
@@ -27,18 +29,25 @@ class GroupWidget extends PositionedWidget { | |
} | ||
} | ||
|
||
class GroupWidgetState extends PositionedWidgetState { | ||
class GroupWidgetState extends PositionedWidgetState with HasConnections { | ||
final Group group; | ||
|
||
GroupWidgetState(this.group) : super(group) { | ||
group.changed.connect(() { | ||
connect(group.changed, () { | ||
setState(() {}); | ||
}); | ||
|
||
group.titleChanged.connect(() { | ||
connect(group.titleChanged, () { | ||
setState(() {}); | ||
}); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
disconnect(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget buildContents(BuildContext ctx) { | ||
final titleBarWidget = TitleBarWidget(group.titlebar); | ||
|