Comments (7)
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.
from nativeshell.
Should be fixed by 869b4a8. You can try to specify the revision in your pubspec.yaml to see if it works for you.
from nativeshell.
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 menu.update()
. It is much better that way, as it will only update the parts of platform menu that have actually changed.
I.e.
late Menu menu;
@override
void initState() {
super.initState();
menu = Menu(_buildMenu);
window.setWindowMenu(menu);
notifier.addListener(_onDocumentOrComposerUpdated);
}
void _onDocumentOrComposerUpdated() {
menu.update();
}
from nativeshell.
I'll try to come up with a reproducible sample of the bug.
I just tried menu.update()
. It doesn't update the menu for some reason.
from nativeshell.
menu.update()
definitely should update the menu. If it doesn't for any reason it is a bug. If you can provide any code that I can use to reproduce the problem that'd be great!
from nativeshell.
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,
),
);
}
}
from nativeshell.
It works great! Thanks!
from nativeshell.
Related Issues (20)
- Failed to interact with file_selector plugin HOT 2
- I see 'MinimizeWindow' exists, but unsure of the best way to call it? HOT 2
- Possible incompatibility with the dart package Get? HOT 1
- [Request] Allow MenuBuilder to take in a BuildContext HOT 1
- Possability of having a persistent taskbar icon to launch GUI?
- NativeShell degrades performance compared to custom embedding HOT 3
- Crashes on multiple monitors in Windows HOT 4
- Is there any way to lower the minimum supported version of macOS HOT 1
- way to run existing flutter code HOT 4
- How to specify libflutter location
- Frameless windows are not resizable on macOS
- Fails to build on apple silicon with Flutter 3.0.0 HOT 2
- The Flutter Attach to Process gets stuck on Waiting... HOT 3
- Invalid read causes segmentation fault HOT 3
- std::rc::Weak<ContextImpl>` cannot be sent between threads safely
- std::rc::Weak<ContextImpl>` cannot be sent between threads safely
- MenuItem clash with flutter widget of the same name HOT 1
- Getting an error when trying to run the examples HOT 2
- Build Error on MacOS 13.2.1 - cargo run or cargo run --release unable to build and run the flutter app for example provided
- Issues with native plugin `media_kit`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nativeshell.