-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Labels
featureA new feature or requestA new feature or requestneeds triageIssue requires triageIssue requires triageproduct: very_good_flutter_pluginChanges that affect the Very Good Flutter Plugin template.Changes that affect the Very Good Flutter Plugin template.
Description
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
endThe 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: trueThose are of cause not all changes, but that should reflect the most relevant.
alestiago
Metadata
Metadata
Assignees
Labels
featureA new feature or requestA new feature or requestneeds triageIssue requires triageIssue requires triageproduct: very_good_flutter_pluginChanges that affect the Very Good Flutter Plugin template.Changes that affect the Very Good Flutter Plugin template.
Type
Projects
Status
Needs Triage