diff --git a/.github/workflows/my_plugin_macos.yaml b/.github/workflows/my_plugin_macos.yaml new file mode 100644 index 0000000..4b0dfb7 --- /dev/null +++ b/.github/workflows/my_plugin_macos.yaml @@ -0,0 +1,21 @@ +name: my_plugin_macos + +on: + pull_request: + paths: + - ".github/workflows/my_plugin_macos.yaml" + - "src/my_plugin_macos/**" + push: + branches: + - main + paths: + - ".github/workflows/my_plugin_macos.yaml" + - "src/my_plugin_macos/**" + +jobs: + build: + uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1 + with: + flutter_channel: stable + flutter_version: 2.10.1 + working_directory: src/my_plugin_macos diff --git a/src/my_plugin_macos/.gitignore b/src/my_plugin_macos/.gitignore new file mode 100644 index 0000000..53e92cc --- /dev/null +++ b/src/my_plugin_macos/.gitignore @@ -0,0 +1,3 @@ +.packages +.flutter-plugins +pubspec.lock diff --git a/src/my_plugin_macos/CHANGELOG.md b/src/my_plugin_macos/CHANGELOG.md new file mode 100644 index 0000000..1455983 --- /dev/null +++ b/src/my_plugin_macos/CHANGELOG.md @@ -0,0 +1,3 @@ +# 0.1.0+1 + +- Initial release of this plugin. \ No newline at end of file diff --git a/src/my_plugin_macos/LICENSE b/src/my_plugin_macos/LICENSE new file mode 100644 index 0000000..bba8e50 --- /dev/null +++ b/src/my_plugin_macos/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Very Good Ventures + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/my_plugin_macos/README.md b/src/my_plugin_macos/README.md new file mode 100644 index 0000000..58fec16 --- /dev/null +++ b/src/my_plugin_macos/README.md @@ -0,0 +1,14 @@ +# my\_plugin\_macos + +[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link] + +The macos implementation of `my_plugin`. + +## Usage + +This package is [endorsed][endorsed_link], which means you can simply use `my_plugin` +normally. This package will be automatically included in your app when you do. + +[endorsed_link]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin +[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg +[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis \ No newline at end of file diff --git a/src/my_plugin_macos/analysis_options.yaml b/src/my_plugin_macos/analysis_options.yaml new file mode 100644 index 0000000..44aef9a --- /dev/null +++ b/src/my_plugin_macos/analysis_options.yaml @@ -0,0 +1 @@ +include: package:very_good_analysis/analysis_options.2.4.0.yaml diff --git a/src/my_plugin_macos/lib/my_plugin_macos.dart b/src/my_plugin_macos/lib/my_plugin_macos.dart new file mode 100644 index 0000000..f340836 --- /dev/null +++ b/src/my_plugin_macos/lib/my_plugin_macos.dart @@ -0,0 +1,20 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; +import 'package:my_plugin_platform_interface/my_plugin_platform_interface.dart'; + +/// The MacOS implementation of [MyPluginPlatform]. +class MyPluginMacOS extends MyPluginPlatform { + /// The method channel used to interact with the native platform. + @visibleForTesting + final methodChannel = const MethodChannel('my_plugin_macos'); + + /// Registers this class as the default instance of [MyPluginPlatform] + static void registerWith() { + MyPluginPlatform.instance = MyPluginMacOS(); + } + + @override + Future getPlatformName() { + return methodChannel.invokeMethod('getPlatformName'); + } +} diff --git a/src/my_plugin_macos/macos/Classes/MyPluginPlugin.swift b/src/my_plugin_macos/macos/Classes/MyPluginPlugin.swift new file mode 100644 index 0000000..5e4a453 --- /dev/null +++ b/src/my_plugin_macos/macos/Classes/MyPluginPlugin.swift @@ -0,0 +1,21 @@ +import FlutterMacOS +import Foundation + +public class MyPluginPlugin: NSObject, FlutterPlugin { + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel( + name: "my_plugin_macos", + binaryMessenger: registrar.messenger) + let instance = MyPluginPlugin() + registrar.addMethodCallDelegate(instance, channel: channel) + } + + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + switch call.method { + case "getPlatformName": + result("MacOS") + default: + result(FlutterMethodNotImplemented) + } + } +} diff --git a/src/my_plugin_macos/macos/my_plugin_macos.podspec b/src/my_plugin_macos/macos/my_plugin_macos.podspec new file mode 100644 index 0000000..5b54b62 --- /dev/null +++ b/src/my_plugin_macos/macos/my_plugin_macos.podspec @@ -0,0 +1,22 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# +Pod::Spec.new do |s| + s.name = 'my_plugin_macos' + s.version = '0.0.1' + s.summary = 'A macOS implementation of the my_plugin plugin.' + s.description = <<-DESC + A macOS implementation of the my_plugin plugin. + DESC + s.homepage = 'http://example.com' + s.license = { :type => 'BSD', :file => '../LICENSE' } + s.author = { 'Your Company' => 'email@example.com' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.dependency 'FlutterMacOS' + + s.platform = :osx + s.osx.deployment_target = '10.11' + s.swift_version = '5.0' +end + diff --git a/src/my_plugin_macos/pubspec.yaml b/src/my_plugin_macos/pubspec.yaml new file mode 100644 index 0000000..6d65447 --- /dev/null +++ b/src/my_plugin_macos/pubspec.yaml @@ -0,0 +1,27 @@ +name: my_plugin_macos +description: MacOS implementation of the my_plugin plugin +version: 0.1.0+1 +publish_to: none + +environment: + sdk: ">=2.12.0 <3.0.0" + flutter: ">=2.0.0" + +flutter: + plugin: + implements: my_plugin + platforms: + macos: + pluginClass: MyPluginPlugin + dartPluginClass: MyPluginMacOS + +dependencies: + flutter: + sdk: flutter + my_plugin_platform_interface: + path: ../my_plugin_platform_interface + +dev_dependencies: + flutter_test: + sdk: flutter + very_good_analysis: ^2.4.0 diff --git a/src/my_plugin_macos/test/my_plugin_macos_test.dart b/src/my_plugin_macos/test/my_plugin_macos_test.dart new file mode 100644 index 0000000..c0f8e49 --- /dev/null +++ b/src/my_plugin_macos/test/my_plugin_macos_test.dart @@ -0,0 +1,44 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:my_plugin_macos/my_plugin_macos.dart'; +import 'package:my_plugin_platform_interface/my_plugin_platform_interface.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group('MyPluginMacOS', () { + const kPlatformName = 'MacOS'; + late MyPluginMacOS myPlugin; + late List log; + + setUp(() async { + myPlugin = MyPluginMacOS(); + + log = []; + TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger + .setMockMethodCallHandler(myPlugin.methodChannel, (methodCall) async { + log.add(methodCall); + switch (methodCall.method) { + case 'getPlatformName': + return kPlatformName; + default: + return null; + } + }); + }); + + test('can be registered', () { + MyPluginMacOS.registerWith(); + expect(MyPluginPlatform.instance, isA()); + }); + + test('getPlatformName returns correct name', () async { + final name = await myPlugin.getPlatformName(); + expect( + log, + [isMethodCall('getPlatformName', arguments: null)], + ); + expect(name, equals(kPlatformName)); + }); + }); +}