Skip to content
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

feat: One module for iOS and MacOS instead of two #42

Open
1 task
rekire opened this issue Feb 23, 2024 · 0 comments
Open
1 task

feat: One module for iOS and MacOS instead of two #42

rekire opened this issue Feb 23, 2024 · 0 comments
Labels
feature A new feature or request needs triage Issue requires triage product: very_good_flutter_plugin Changes that affect the Very Good Flutter Plugin template.

Comments

@rekire
Copy link

rekire commented Feb 23, 2024

Migrated from VeryGoodOpenSource/very_good_flutter_plugin#154

Description

There is a way to declare that you want to use the same code for iOS and MacOS. There was a proposal which explained it quite well. This is already in use e.g. for the path_provider package. Which this feature you can avoid a lot of duplicated code (I expect that you do the same on both platforms).

Requirements

  • Rewrite the plugin to support that

Additional Context

Here is an example how the MyPlugin.swift should look like afterwards:

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

public class MyPlugin: NSObject, FlutterPlugin {
    public static func register(with registrar: FlutterPluginRegistrar) {
        // Workaround for https://github.com/flutter/flutter/issues/118103.
#if os(iOS)
        let messenger = registrar.messenger()
#else
        let messenger = registrar.messenger
#endif
        let channel = FlutterMethodChannel(
            name: "my_plugin_darwin",
            binaryMessenger: messenger)
        let instance = MyPlugin()
        registrar.addMethodCallDelegate(instance, channel: channel)
    }

//...

The podfile should look like this:

Pod::Spec.new do |s|
  s.name             = 'my_plugin_darwin'
  s.version          = '0.0.1'
  s.summary          = 'The iOS and MacOS implementation of my plugin.'
  s.description      = <<-DESC
  The iOS and MacOS implementation of the my plugin.
                       DESC
  s.homepage         = 'http://example.com'
  s.license          = { :type => 'BSD', :file => '../LICENSE' }
  s.author           = { 'Your Company' => '[email protected]' }
  s.source           = { :path => '.' }
  s.source_files = 'Classes/**/*'

  s.swift_version = '5.0'

  s.ios.dependency 'Flutter'
  s.osx.dependency 'FlutterMacOS'
  s.ios.deployment_target = '11.0' # or what ever version you need
  s.osx.deployment_target = '11.0' # or what ever version you need
end

The my_plugin_darwin/pubspec.yaml like this:

flutter:
  plugin:
    implements: my_plugin
    platforms:
      ios:
        pluginClass: MyPlugin
        dartPluginClass: MyPluginDarwin
        sharedDarwinSource: true
      macos:
        pluginClass: MyPlugin
        dartPluginClass: MyPluginDarwin
        sharedDarwinSource: true

Those are of cause not all changes, but that should reflect the most relevant.

@rekire rekire added the feature A new feature or request label Feb 23, 2024
@alestiago alestiago added product: very_good_flutter_plugin Changes that affect the Very Good Flutter Plugin template. needs triage Issue requires triage labels Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature or request needs triage Issue requires triage product: very_good_flutter_plugin Changes that affect the Very Good Flutter Plugin template.
Projects
Status: Needs Triage
Development

No branches or pull requests

2 participants