fix: notifier disposed but in use (#6586)

This commit is contained in:
Mathias Mogensen 2024-10-21 00:21:25 +02:00 committed by GitHub
parent 6340174927
commit 1d9876a6eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -56,7 +56,7 @@ class _CommandPaletteController extends StatefulWidget {
}
class _CommandPaletteControllerState extends State<_CommandPaletteController> {
late final ValueNotifier<bool> _toggleNotifier = widget.notifier;
late ValueNotifier<bool> _toggleNotifier = widget.notifier;
bool _isOpen = false;
@override
@ -71,6 +71,16 @@ class _CommandPaletteControllerState extends State<_CommandPaletteController> {
super.dispose();
}
@override
void didUpdateWidget(_CommandPaletteController oldWidget) {
if (oldWidget.notifier != widget.notifier) {
oldWidget.notifier.removeListener(_onToggle);
_toggleNotifier = widget.notifier;
_toggleNotifier.addListener(_onToggle);
}
super.didUpdateWidget(oldWidget);
}
void _onToggle() {
if (_toggleNotifier.value && !_isOpen) {
_isOpen = true;