-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhandled Exception: '_currentHandle != null && _materializer != null': is not true. #76
Comments
This seems like a bug. A minimal reproducible example would help. However if you need to update menu, just store the menu instance (that you set as window menu) and call I.e. late Menu menu;
@override
void initState() {
super.initState();
menu = Menu(_buildMenu);
window.setWindowMenu(menu);
notifier.addListener(_onDocumentOrComposerUpdated);
}
void _onDocumentOrComposerUpdated() {
menu.update();
} |
I'll try to come up with a reproducible sample of the bug. |
|
Here's something very similar to what I'm doing. The command of interest is the "save" command. If the text controller's selection is collapsed, then its action is null, otherwise, it's set to a callback. Setting a new menu every time works (use that to reproduce the previous issue), but not using menu update. class TextFieldMenuBuilder extends StatefulWidget {
const TextFieldMenuBuilder({
Key? key,
required this.child,
}) : super(key: key);
final Widget child;
@override
_TextFieldMenuBuilderState createState() => _TextFieldMenuBuilderState();
}
class _TextFieldMenuBuilderState extends State<TextFieldMenuBuilder> {
late Menu _menu;
late final TextEditingController controller;
@override
void initState() {
super.initState();
controller = TextEditingController();
controller.addListener(_onTextOrSelectionChanged);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_menu = Menu(_buildMenu);
Window.of(context).setWindowMenu(_menu);
}
void _onTextOrSelectionChanged() {
_menu.update();
}
List<MenuItem> _buildMenu() {
return [
if (Platform.isMacOS)
MenuItem.children(
title: 'App',
children: [
MenuItem.withRole(role: MenuItemRole.hide),
],
),
MenuItem.children(
title: '&File',
children: [
MenuItem(title: 'New', accelerator: cmdOrCtrl + 'n', action: null),
MenuItem.separator(),
// COMMAND OF INTEREST
MenuItem(
title: 'Save',
accelerator: cmdOrCtrl + 's',
action: controller.selection.isCollapsed ? null : () {},
),
],
),
];
}
@override
Widget build(BuildContext context) {
return Center(
child: TextField(
controller: controller,
),
);
}
} |
Thank you for the snippet. I was able to reproduce the problem. The issue is that NativeShell doesn't detect change from enabled to disabled, so it doesn't update the menu. If you for example modify the menu item title, i.e. MenuItem(
title: controller.selection.isCollapsed ? 'Save_' : 'Save', // change title when section changes
accelerator: cmdOrCtrl + 's',
action: controller.selection.isCollapsed ? null : () {},
), it will work as expected. Shouldn't be too difficult to fix. |
Should be fixed by 869b4a8. You can try to specify the revision in your pubspec.yaml to see if it works for you. |
It works great! Thanks! |
In my application, I update the Window menu whenever a
ChangeNotifier
notifies its listeners. It looks something like this:This works, but I keep getting this error in the console:
Error and Stacktrace
The text was updated successfully, but these errors were encountered: