{"id":13491122,"url":"https://github.com/mynameiskenlee/flutter_macos_menubar_example","last_synced_at":"2025-03-28T07:31:56.278Z","repository":{"id":41443192,"uuid":"468821718","full_name":"mynameiskenlee/flutter_macos_menubar_example","owner":"mynameiskenlee","description":"starter template for building macOS menubar app with flutter and AppKit","archived":false,"fork":false,"pushed_at":"2024-01-16T06:26:40.000Z","size":2069,"stargazers_count":131,"open_issues_count":4,"forks_count":15,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-31T04:35:05.062Z","etag":null,"topics":["appkit","flutter","flutter-example-app","flutter-macos","flutter-template","macos","menubar-app"],"latest_commit_sha":null,"homepage":"https://www.reddit.com/r/FlutterDev/comments/g7aavn/creating_a_menubar_app_for_macos/","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mynameiskenlee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-11T16:24:28.000Z","updated_at":"2024-10-17T01:06:21.000Z","dependencies_parsed_at":"2024-01-16T08:42:08.177Z","dependency_job_id":"ec3436e2-0c19-4514-85b0-9ff7afd70f1c","html_url":"https://github.com/mynameiskenlee/flutter_macos_menubar_example","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mynameiskenlee%2Fflutter_macos_menubar_example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mynameiskenlee%2Fflutter_macos_menubar_example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mynameiskenlee%2Fflutter_macos_menubar_example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mynameiskenlee%2Fflutter_macos_menubar_example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mynameiskenlee","download_url":"https://codeload.github.com/mynameiskenlee/flutter_macos_menubar_example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245989388,"owners_count":20705820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appkit","flutter","flutter-example-app","flutter-macos","flutter-template","macos","menubar-app"],"created_at":"2024-07-31T19:00:53.738Z","updated_at":"2025-03-28T07:31:52.774Z","avatar_url":"https://github.com/mynameiskenlee.png","language":"Dart","funding_links":[],"categories":["Dart"],"sub_categories":[],"readme":"# flutter_macos_menubar_example\n\nstarter template for building menubar app in flutter\n\n\u003cimg src=\"https://github.com/mynameiskenlee/flutter_macos_menubar_example/blob/master/Demo.png?raw=true\" width=\"250\" /\u003e\n\nUse [multi_windows](https://github.com/mynameiskenlee/flutter_macos_menubar_example/tree/multi_windows) branch for example with addtional windows (select include all branches when using this template)\n\n![multi_windows demo](multi_window.gif)\n\n-------------------------------------------------------\n## Getting Started (for single window menu bar app only)\nuse this template or follow the following step in your flutter project:\n\n1. Change to Content of macos/Runner/AppDelegate.swift\n```[language=swift]\nimport Cocoa\nimport FlutterMacOS\n\n@NSApplicationMain\nclass AppDelegate: FlutterAppDelegate {\n  var statusBar: StatusBarController?\n  var popover = NSPopover.init()\n  override init() {\n    popover.behavior = NSPopover.Behavior.transient //to make the popover hide when the user clicks outside of it\n  }\n  override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -\u003e Bool {\n    return false\n  }\n  override func applicationDidFinishLaunching(_ aNotification: Notification) {\n    let controller: FlutterViewController =\n      mainFlutterWindow?.contentViewController as! FlutterViewController\n    popover.contentSize = NSSize(width: 360, height: 360) //change this to your desired size\n    popover.contentViewController = controller //set the content view controller for the popover to flutter view controller\n    statusBar = StatusBarController.init(popover)\n    mainFlutterWindow.close() //close the default flutter window\n    super.applicationDidFinishLaunching(aNotification)\n  }\n}\n```\n2. Add a new Swift file named 'StatusBarController.swift' in XCode\n![Xcode \u003e File \u003e New \u003e File...](Step2.1.png)\n![Select Swift File](Step2.2.png)\n![Name it StatusBarController.swift](Step2.3.png)\n3. Add the following code to the StatusBarController.swift\n```[language=swift]\nimport AppKit\n\nclass StatusBarController {\n    private var statusBar: NSStatusBar\n    private var statusItem: NSStatusItem\n    private var popover: NSPopover\n    \n    init(_ popover: NSPopover) {\n        self.popover = popover\n        statusBar = NSStatusBar.init()\n        statusItem = statusBar.statusItem(withLength: 28.0)\n        \n        if let statusBarButton = statusItem.button {\n            statusBarButton.image = #imageLiteral(resourceName: \"AppIcon\") //change this to your desired image\n            statusBarButton.image?.size = NSSize(width: 18.0, height: 18.0)\n            statusBarButton.image?.isTemplate = true\n            statusBarButton.action = #selector(togglePopover(sender:))\n            statusBarButton.target = self\n        }\n    }\n    \n    @objc func togglePopover(sender: AnyObject) {\n        if(popover.isShown) {\n            hidePopover(sender)\n        }\n        else {\n            showPopover(sender)\n        }\n    }\n    \n    func showPopover(_ sender: AnyObject) {\n        if let statusBarButton = statusItem.button {\n            popover.show(relativeTo: statusBarButton.bounds, of: statusBarButton, preferredEdge: NSRectEdge.maxY)\n        }\n    }\n    \n    func hidePopover(_ sender: AnyObject) {\n        popover.performClose(sender)\n    }\n}\n```\n4. Add the following to macos/Runner/Info.plist to hide the dock icon and application menu\n```[language=xml]\n\u003ckey\u003eLSUIElement\u003c/key\u003e\n\u003ctrue/\u003e\n```\nTo close the app programmatically, use the following code\n```[language=dart]\nexit(0)\n```\n5. Done!\nYou can now build your menubar app with flutter.\n![Complete](Demo.png)\n-------------------------------------------------------\n\nThis project is a starting point for a Flutter menubar application in macOS.\n\nA few resources to get you started if this is your first Flutter project:\n\n- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)\n- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)\n\nFor help getting started with Flutter, view our\n[online documentation](https://flutter.dev/docs), which offers tutorials,\nsamples, guidance on mobile development, and a full API reference.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmynameiskenlee%2Fflutter_macos_menubar_example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmynameiskenlee%2Fflutter_macos_menubar_example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmynameiskenlee%2Fflutter_macos_menubar_example/lists"}