Skip to content

Commit eeda2f7

Browse files
authored
Add Menu.isPluginAvailable to allow query of whether menus are available on the platform. (flutter#32795)
Added a "Menu.isPluginAvailable" call to allow the framework to query whether a plugin for creating platform menus is available on the current platform. This will allow the framework MenuBar.adaptive constructor to determine, based on the availability on the platform of the plugin, whether or not to render platform menus. This replaces the old way, which was just to hard code which platforms support it (i.e. just macOS), but that won't work well if someone adds a plugin that supports a particular platform that isn't macOS.
1 parent 2338990 commit eeda2f7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.mm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
// Channel constants
1414
static NSString* const kChannelName = @"flutter/menu";
15+
static NSString* const kIsPluginAvailableMethod = @"Menu.isPluginAvailable";
1516
static NSString* const kMenuSetMenusMethod = @"Menu.setMenus";
1617
static NSString* const kMenuSelectedCallbackMethod = @"Menu.selectedCallback";
1718
static NSString* const kMenuOpenedMethod = @"Menu.opened";
@@ -377,7 +378,9 @@ - (void)flutterMenuItemSelected:(id)sender {
377378
}
378379

379380
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
380-
if ([call.method isEqualToString:kMenuSetMenusMethod]) {
381+
if ([call.method isEqualToString:kIsPluginAvailableMethod]) {
382+
result(@YES);
383+
} else if ([call.method isEqualToString:kMenuSetMenusMethod]) {
381384
NSDictionary* menus = call.arguments;
382385
[self setMenus:menus];
383386
result(nil);

shell/platform/darwin/macos/framework/Source/FlutterMenuPluginTest.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ - (bool)testSetMenu {
106106
],
107107
};
108108

109+
__block id available = @NO;
110+
[plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"Menu.isPluginAvailable"
111+
arguments:nil]
112+
result:^(id _Nullable result) {
113+
available = result;
114+
}];
115+
116+
EXPECT_TRUE(available);
117+
109118
[plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"Menu.setMenus"
110119
arguments:testMenus]
111120
result:^(id _Nullable result){

0 commit comments

Comments
 (0)