Skip to content

Allow creating "darwin" (shared codebase for ios/macos) plugins directly in flutter create #161019

Closed

Description

@mgenware

Use case

Right now when you create darwin plugin, you have to start with an ios or macos template. Then follow the docs. There are clearly some differences between macos and ios templates. Which one is preferred to start with? Why not just add a darwin platform?

Proposal

Simply make 'darwin' a valid platform option and create a darwin project directly from CLI.

flutter create --template=plugin --platforms="darwin" my_plugin

Activity

  1. added
    in triagePresently being triaged by the triage team
    platform-iosiOS applications specifically
    toolAffects the "flutter" command-line tool. See also t: labels.
    platform-macosBuilding on or for macOS specifically
    c: proposalA detailed proposal for a change to Flutter
    a: pluginsSupport for writing, building, and running plugin packages
    and removed
    in triagePresently being triaged by the triage team
    on Jan 3, 2025
  2. added
    P2Important issues not at the top of the work list
    on Jan 7, 2025
  3. self-assigned this
    on Sep 15, 2025
  4. added
    ⏳Bot is counting down the days until it unassigns the issue
    on Sep 16, 2025
  5. flutter-triage-bot commented on Sep 16, 2025

    @flutter-triage-bot

    This issue is assigned to @okorohelijah but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  6. flutter-triage-bot commented on Sep 16, 2025

    @flutter-triage-bot

    This issue was assigned to @okorohelijah but has had no status updates in a long time. To remove any ambiguity about whether the issue is being worked on, the assignee was removed.

  7. removed
    ⏳Bot is counting down the days until it unassigns the issue
    on Sep 16, 2025
  8. stuartmorgan-g commented on Sep 16, 2025

    @stuartmorgan-g
    Contributor

    Commenting to convince the bot not to unassign.

  9. mgenware commented on Oct 2, 2025

    @mgenware
    Author

    Had to create a darwin plugin again. Here are all steps.

    • Create an iOS plugin.
    • Rename ios folder to darwin.

    For legacy cocoapods support.

    Update <your plugin>.podspec, replace iOS config with iOS and macOS config:

      s.ios.dependency 'Flutter'
      s.osx.dependency 'FlutterMacOS'
    
      s.ios.deployment_target = '11.0'
      s.osx.deployment_target = '10.15'
    
      s.ios.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
      s.osx.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
    

    For swift pm support, add minimum macOS version in package.swift platforms field:

        platforms: [
            .iOS("14.0"),
            .macOS("10.15")
        ],

    In pubspec.yaml, add sharedDarwinSource:

      plugin:
        platforms:
          ios:
            pluginClass: YourPlugin
            sharedDarwinSource: true
          macos:
            pluginClass: YourPlugin
            sharedDarwinSource: true

    In your plugin implementation swift code. Replace imports with macOS support:

    import Foundation
    
    #if os(iOS)
      import Flutter
    #elseif os(macOS)
      import FlutterMacOS
    #endif

    In plugin register func, there's some nuances to handle:

        #if os(iOS)
          let binaryMessenger = registrar.messenger()
        #elseif os(macOS)
          let binaryMessenger = registrar.messenger
        #endif
        let channel = FlutterMethodChannel(
          name: "<your_plugin>", binaryMessenger: binaryMessenger)

    Now, you should be able to compile both platforms with a shared codebase.

  10. added a commit that references this issue on Nov 27, 2025
    0b191ba
  11. added a commit that references this issue on Dec 2, 2025
    c8c60ce
  12. added a commit that references this issue on Dec 10, 2025
    7b11c8b
  13. github-actions commented on Dec 11, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  14. locked as resolved and limited conversation to collaborators on Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: pluginsSupport for writing, building, and running plugin packagesc: proposalA detailed proposal for a change to Flutterplatform-iosiOS applications specificallyplatform-macosBuilding on or for macOS specificallyr: fixedIssue is closed as already fixed in a newer versionteam-ecosystemOwned by Ecosystem teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-ecosystemTriaged by Ecosystem team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions