From b79561e4ed96b7028be1740596f41d0be6e0a851 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Tue, 15 Feb 2022 12:55:27 -0600 Subject: [PATCH] feat(ios): create my_plugin_ios (#3) --- .github/workflows/my_plugin_ios.yaml | 21 +++++++++ src/my_plugin_ios/CHANGELOG.md | 3 ++ src/my_plugin_ios/LICENSE | 21 +++++++++ src/my_plugin_ios/README.md | 14 ++++++ .../ios/Classes/MyPluginPlugin.h | 4 ++ .../ios/Classes/MyPluginPlugin.m | 18 ++++++++ src/my_plugin_ios/ios/my_plugin_ios.podspec | 21 +++++++++ src/my_plugin_ios/lib/my_plugin_ios.dart | 20 +++++++++ src/my_plugin_ios/pubspec.yaml | 28 ++++++++++++ .../test/my_plugin_ios_test.dart | 44 +++++++++++++++++++ 10 files changed, 194 insertions(+) create mode 100644 .github/workflows/my_plugin_ios.yaml create mode 100644 src/my_plugin_ios/CHANGELOG.md create mode 100644 src/my_plugin_ios/LICENSE create mode 100644 src/my_plugin_ios/README.md create mode 100644 src/my_plugin_ios/ios/Classes/MyPluginPlugin.h create mode 100644 src/my_plugin_ios/ios/Classes/MyPluginPlugin.m create mode 100644 src/my_plugin_ios/ios/my_plugin_ios.podspec create mode 100644 src/my_plugin_ios/lib/my_plugin_ios.dart create mode 100644 src/my_plugin_ios/pubspec.yaml create mode 100644 src/my_plugin_ios/test/my_plugin_ios_test.dart diff --git a/.github/workflows/my_plugin_ios.yaml b/.github/workflows/my_plugin_ios.yaml new file mode 100644 index 0000000..71aea72 --- /dev/null +++ b/.github/workflows/my_plugin_ios.yaml @@ -0,0 +1,21 @@ +name: my_plugin_ios + +on: + pull_request: + paths: + - ".github/workflows/my_plugin_ios.yaml" + - "src/my_plugin_ios/**" + push: + branches: + - main + paths: + - ".github/workflows/my_plugin_ios.yaml" + - "src/my_plugin_ios/**" + +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_ios diff --git a/src/my_plugin_ios/CHANGELOG.md b/src/my_plugin_ios/CHANGELOG.md new file mode 100644 index 0000000..1455983 --- /dev/null +++ b/src/my_plugin_ios/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_ios/LICENSE b/src/my_plugin_ios/LICENSE new file mode 100644 index 0000000..bba8e50 --- /dev/null +++ b/src/my_plugin_ios/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_ios/README.md b/src/my_plugin_ios/README.md new file mode 100644 index 0000000..ee62cf5 --- /dev/null +++ b/src/my_plugin_ios/README.md @@ -0,0 +1,14 @@ +# my_plugin_ios + +[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link] + +The ios 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_ios/ios/Classes/MyPluginPlugin.h b/src/my_plugin_ios/ios/Classes/MyPluginPlugin.h new file mode 100644 index 0000000..c2cf46e --- /dev/null +++ b/src/my_plugin_ios/ios/Classes/MyPluginPlugin.h @@ -0,0 +1,4 @@ +#import + +@interface MyPluginPlugin : NSObject +@end diff --git a/src/my_plugin_ios/ios/Classes/MyPluginPlugin.m b/src/my_plugin_ios/ios/Classes/MyPluginPlugin.m new file mode 100644 index 0000000..13eb3f9 --- /dev/null +++ b/src/my_plugin_ios/ios/Classes/MyPluginPlugin.m @@ -0,0 +1,18 @@ +#import "MyPluginPlugin.h" + +@implementation MyPluginPlugin + ++ (void)registerWithRegistrar:(NSObject *)registrar { + FlutterMethodChannel *channel = + [FlutterMethodChannel methodChannelWithName:@"my_plugin_ios" + binaryMessenger:registrar.messenger]; + [channel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) { + if ([@"getPlatformName" isEqualToString:call.method]) { + result(@"iOS"); + } else { + result(FlutterMethodNotImplemented); + } + }]; +} + +@end \ No newline at end of file diff --git a/src/my_plugin_ios/ios/my_plugin_ios.podspec b/src/my_plugin_ios/ios/my_plugin_ios.podspec new file mode 100644 index 0000000..62c4c9a --- /dev/null +++ b/src/my_plugin_ios/ios/my_plugin_ios.podspec @@ -0,0 +1,21 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# +Pod::Spec.new do |s| + s.name = 'my_plugin_ios' + s.version = '0.0.1' + s.summary = 'An iOS implementation of the my_plugin plugin.' + s.description = <<-DESC + An iOS 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.public_header_files = 'Classes/**/*.h' + s.dependency 'Flutter' + + s.platform = :ios, '9.0' + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } +end diff --git a/src/my_plugin_ios/lib/my_plugin_ios.dart b/src/my_plugin_ios/lib/my_plugin_ios.dart new file mode 100644 index 0000000..91d6328 --- /dev/null +++ b/src/my_plugin_ios/lib/my_plugin_ios.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 iOS implementation of [MyPluginPlatform]. +class MyPluginIOS extends MyPluginPlatform { + /// The method channel used to interact with the native platform. + @visibleForTesting + final methodChannel = const MethodChannel('my_plugin_ios'); + + /// Registers this class as the default instance of [MyPluginPlatform] + static void registerWith() { + MyPluginPlatform.instance = MyPluginIOS(); + } + + @override + Future getPlatformName() { + return methodChannel.invokeMethod('getPlatformName'); + } +} diff --git a/src/my_plugin_ios/pubspec.yaml b/src/my_plugin_ios/pubspec.yaml new file mode 100644 index 0000000..699271a --- /dev/null +++ b/src/my_plugin_ios/pubspec.yaml @@ -0,0 +1,28 @@ +name: my_plugin_ios +description: iOS implementation of the my_plugin plugin +version: 0.1.0+1 +publish_to: none + +environment: + sdk: ">=2.14.0 <3.0.0" + flutter: ">=2.5.0" + +flutter: + plugin: + implements: my_plugin + platforms: + ios: + pluginClass: MyPluginPlugin + dartPluginClass: MyPluginIOS + +dependencies: + flutter: + sdk: flutter + my_plugin_platform_interface: + path: ../my_plugin_platform_interface + +dev_dependencies: + flutter_test: + sdk: flutter + plugin_platform_interface: ^2.0.0 + very_good_analysis: ^2.4.0 diff --git a/src/my_plugin_ios/test/my_plugin_ios_test.dart b/src/my_plugin_ios/test/my_plugin_ios_test.dart new file mode 100644 index 0000000..2b4a804 --- /dev/null +++ b/src/my_plugin_ios/test/my_plugin_ios_test.dart @@ -0,0 +1,44 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:my_plugin_ios/my_plugin_ios.dart'; +import 'package:my_plugin_platform_interface/my_plugin_platform_interface.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group('MyPluginIOS', () { + const kPlatformName = 'iOS'; + late MyPluginIOS myPlugin; + late List log; + + setUp(() async { + myPlugin = MyPluginIOS(); + + 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', () { + MyPluginIOS.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)); + }); + }); +}