From 628e986a0015e34df19a12942be01370a230645d Mon Sep 17 00:00:00 2001 From: Alann Maulana Date: Sun, 1 Aug 2021 15:38:59 +0700 Subject: [PATCH] Fix pana (#1) * remove import external libs on pluginClass * add macos dummy plugin * add android dummy plugin * add ios dummy plugin * update lib * Update pubspec.yaml * update example --- android/.gitignore | 8 ++++ android/build.gradle | 40 +++++++++++++++++++ android/gradle.properties | 3 ++ .../gradle/wrapper/gradle-wrapper.properties | 5 +++ android/settings.gradle | 1 + android/src/main/AndroidManifest.xml | 3 ++ .../com/mesosfer/flimer/FlimerPlugin.kt | 32 +++++++++++++++ example/ios/Podfile.lock | 6 +++ example/macos/Podfile.lock | 6 +++ example/pubspec.lock | 2 +- ios/.gitignore | 37 +++++++++++++++++ ios/Assets/.gitkeep | 0 ios/Classes/FlimerPlugin.h | 4 ++ ios/Classes/FlimerPlugin.m | 15 +++++++ ios/Classes/SwiftFlimerPlugin.swift | 14 +++++++ ios/flimer.podspec | 23 +++++++++++ lib/flimer.dart | 11 ++--- lib/src/flimer_html.dart | 9 +++-- lib/src/flimer_io.dart | 8 ++-- lib/src/flimer_stub.dart | 1 - lib/src/image_source.dart | 8 ++++ macos/Classes/FlimerPlugin.swift | 14 +++++++ macos/flimer.podspec | 22 ++++++++++ pubspec.lock | 2 +- pubspec.yaml | 22 ++++++++++ 25 files changed, 281 insertions(+), 15 deletions(-) create mode 100644 android/.gitignore create mode 100644 android/build.gradle create mode 100644 android/gradle.properties create mode 100644 android/gradle/wrapper/gradle-wrapper.properties create mode 100644 android/settings.gradle create mode 100644 android/src/main/AndroidManifest.xml create mode 100644 android/src/main/kotlin/com/mesosfer/flimer/FlimerPlugin.kt create mode 100644 ios/.gitignore create mode 100644 ios/Assets/.gitkeep create mode 100644 ios/Classes/FlimerPlugin.h create mode 100644 ios/Classes/FlimerPlugin.m create mode 100644 ios/Classes/SwiftFlimerPlugin.swift create mode 100644 ios/flimer.podspec create mode 100644 lib/src/image_source.dart create mode 100644 macos/Classes/FlimerPlugin.swift create mode 100644 macos/flimer.podspec diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 0000000..c6cbe56 --- /dev/null +++ b/android/.gitignore @@ -0,0 +1,8 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/android/build.gradle b/android/build.gradle new file mode 100644 index 0000000..dfb64ec --- /dev/null +++ b/android/build.gradle @@ -0,0 +1,40 @@ +group 'com.mesosfer.flimer' +version '1.0-SNAPSHOT' + +buildscript { + ext.kotlin_version = '1.3.50' + repositories { + google() + jcenter() + } + + dependencies { + classpath 'com.android.tools.build:gradle:4.1.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +rootProject.allprojects { + repositories { + google() + jcenter() + } +} + +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' + +android { + compileSdkVersion 30 + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + defaultConfig { + minSdkVersion 16 + } +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} diff --git a/android/gradle.properties b/android/gradle.properties new file mode 100644 index 0000000..94adc3a --- /dev/null +++ b/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..3c9d085 --- /dev/null +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip diff --git a/android/settings.gradle b/android/settings.gradle new file mode 100644 index 0000000..9b455e8 --- /dev/null +++ b/android/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'flimer' diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..0109249 --- /dev/null +++ b/android/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + diff --git a/android/src/main/kotlin/com/mesosfer/flimer/FlimerPlugin.kt b/android/src/main/kotlin/com/mesosfer/flimer/FlimerPlugin.kt new file mode 100644 index 0000000..679558f --- /dev/null +++ b/android/src/main/kotlin/com/mesosfer/flimer/FlimerPlugin.kt @@ -0,0 +1,32 @@ +package com.mesosfer.flimer + +import androidx.annotation.NonNull + +import io.flutter.embedding.engine.plugins.FlutterPlugin +import io.flutter.plugin.common.MethodCall +import io.flutter.plugin.common.MethodChannel +import io.flutter.plugin.common.MethodChannel.MethodCallHandler +import io.flutter.plugin.common.MethodChannel.Result +import io.flutter.plugin.common.PluginRegistry.Registrar + +/** FlimerPlugin */ +class FlimerPlugin: FlutterPlugin, MethodCallHandler { + /// The MethodChannel that will the communication between Flutter and native Android + /// + /// This local reference serves to register the plugin with the Flutter Engine and unregister it + /// when the Flutter Engine is detached from the Activity + private lateinit var channel : MethodChannel + + override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { + channel = MethodChannel(flutterPluginBinding.binaryMessenger, "flimer") + channel.setMethodCallHandler(this) + } + + override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { + result.notImplemented() + } + + override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { + channel.setMethodCallHandler(null) + } +} diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index a9791df..45a8785 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,19 +1,25 @@ PODS: + - flimer (1.0.0): + - Flutter - Flutter (1.0.0) - image_picker (0.0.1): - Flutter DEPENDENCIES: + - flimer (from `.symlinks/plugins/flimer/ios`) - Flutter (from `Flutter`) - image_picker (from `.symlinks/plugins/image_picker/ios`) EXTERNAL SOURCES: + flimer: + :path: ".symlinks/plugins/flimer/ios" Flutter: :path: Flutter image_picker: :path: ".symlinks/plugins/image_picker/ios" SPEC CHECKSUMS: + flimer: 45e25c3a703196763a4568192fe94684b89f0552 Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c image_picker: e06f7a68f000bd36f552c1847e33cda96ed31f1f diff --git a/example/macos/Podfile.lock b/example/macos/Podfile.lock index d3d5ecd..7f54b8f 100644 --- a/example/macos/Podfile.lock +++ b/example/macos/Podfile.lock @@ -1,20 +1,26 @@ PODS: - file_selector_macos (0.0.1): - FlutterMacOS + - flimer (0.0.1): + - FlutterMacOS - FlutterMacOS (1.0.0) DEPENDENCIES: - file_selector_macos (from `Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos`) + - flimer (from `Flutter/ephemeral/.symlinks/plugins/flimer/macos`) - FlutterMacOS (from `Flutter/ephemeral`) EXTERNAL SOURCES: file_selector_macos: :path: Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos + flimer: + :path: Flutter/ephemeral/.symlinks/plugins/flimer/macos FlutterMacOS: :path: Flutter/ephemeral SPEC CHECKSUMS: file_selector_macos: ff6dc948d4ddd34e8602a1f60b7d0b4cc6051a47 + flimer: 8747c1b2b830ac2f717e89ca593079d49fcd6418 FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424 PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c diff --git a/example/pubspec.lock b/example/pubspec.lock index 33c7b25..021cb76 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -112,7 +112,7 @@ packages: path: ".." relative: true source: path - version: "0.0.1" + version: "1.0.0" flutter: dependency: "direct main" description: flutter diff --git a/ios/.gitignore b/ios/.gitignore new file mode 100644 index 0000000..aa479fd --- /dev/null +++ b/ios/.gitignore @@ -0,0 +1,37 @@ +.idea/ +.vagrant/ +.sconsign.dblite +.svn/ + +.DS_Store +*.swp +profile + +DerivedData/ +build/ +GeneratedPluginRegistrant.h +GeneratedPluginRegistrant.m + +.generated/ + +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 + +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + +xcuserdata + +*.moved-aside + +*.pyc +*sync/ +Icon? +.tags* + +/Flutter/Generated.xcconfig +/Flutter/flutter_export_environment.sh \ No newline at end of file diff --git a/ios/Assets/.gitkeep b/ios/Assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/ios/Classes/FlimerPlugin.h b/ios/Classes/FlimerPlugin.h new file mode 100644 index 0000000..384fc03 --- /dev/null +++ b/ios/Classes/FlimerPlugin.h @@ -0,0 +1,4 @@ +#import + +@interface FlimerPlugin : NSObject +@end diff --git a/ios/Classes/FlimerPlugin.m b/ios/Classes/FlimerPlugin.m new file mode 100644 index 0000000..281714f --- /dev/null +++ b/ios/Classes/FlimerPlugin.m @@ -0,0 +1,15 @@ +#import "FlimerPlugin.h" +#if __has_include() +#import +#else +// Support project import fallback if the generated compatibility header +// is not copied when this plugin is created as a library. +// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816 +#import "flimer-Swift.h" +#endif + +@implementation FlimerPlugin ++ (void)registerWithRegistrar:(NSObject*)registrar { + [SwiftFlimerPlugin registerWithRegistrar:registrar]; +} +@end diff --git a/ios/Classes/SwiftFlimerPlugin.swift b/ios/Classes/SwiftFlimerPlugin.swift new file mode 100644 index 0000000..356a5ff --- /dev/null +++ b/ios/Classes/SwiftFlimerPlugin.swift @@ -0,0 +1,14 @@ +import Flutter +import UIKit + +public class SwiftFlimerPlugin: NSObject, FlutterPlugin { + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel(name: "flimer", binaryMessenger: registrar.messenger()) + let instance = SwiftFlimerPlugin() + registrar.addMethodCallDelegate(instance, channel: channel) + } + + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + result(FlutterMethodNotImplemented) + } +} diff --git a/ios/flimer.podspec b/ios/flimer.podspec new file mode 100644 index 0000000..432bcb8 --- /dev/null +++ b/ios/flimer.podspec @@ -0,0 +1,23 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. +# Run `pod lib lint flimer.podspec` to validate before publishing. +# +Pod::Spec.new do |s| + s.name = 'flimer' + s.version = '1.0.0' + s.summary = 'Flutter plugin for picking images on Mobile, Desktop and Web.' + s.description = <<-DESC +Flutter plugin for picking images on Mobile, Desktop and Web. + DESC + s.homepage = 'https://github.com/eyro-labs/flimer' + s.license = { :file => '../LICENSE' } + s.author = { 'Eyro Labs' => 'me@eyro.co.id' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.dependency 'Flutter' + s.platform = :ios, '8.0' + + # Flutter.framework does not contain a i386 slice. + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } + s.swift_version = '5.0' +end diff --git a/lib/flimer.dart b/lib/flimer.dart index 4936379..2ab8a8f 100644 --- a/lib/flimer.dart +++ b/lib/flimer.dart @@ -1,15 +1,14 @@ import 'dart:async'; -import 'package:image_picker/image_picker.dart'; +import 'package:cross_file/cross_file.dart'; import 'src/flimer_stub.dart' if (dart.library.io) 'src/flimer_io.dart' if (dart.library.html) 'src/flimer_html.dart'; +import 'src/image_source.dart'; -export 'package:file_selector_platform_interface/file_selector_platform_interface.dart' - show XFile; -export 'package:image_picker_platform_interface/image_picker_platform_interface.dart' - show ImageSource; +export 'package:cross_file/cross_file.dart' show XFile; +export 'src/image_source.dart' show ImageSource; export 'src/flimer_stub.dart' if (dart.library.io) 'src/flimer_io.dart' if (dart.library.html) 'src/flimer_html.dart'; @@ -19,6 +18,8 @@ final Flimer flimer = Flimer(); /// Flimer stands for Flutter Image Picker. abstract class Flimer { + static void registerWith() {} + /// Construct flimer using global platform getter. factory Flimer() => getFlimer(); diff --git a/lib/src/flimer_html.dart b/lib/src/flimer_html.dart index b34dfde..b8c93aa 100644 --- a/lib/src/flimer_html.dart +++ b/lib/src/flimer_html.dart @@ -1,14 +1,17 @@ import 'package:flimer/flimer.dart'; -import 'package:image_picker/image_picker.dart'; +import 'package:flutter_web_plugins/flutter_web_plugins.dart'; +import 'package:image_picker/image_picker.dart' as ip; getFlimer() => FlimerHtml(); class FlimerHtml implements Flimer { - final ImagePicker _picker = ImagePicker(); + static void registerWith(Registrar registrar) {} + + final ip.ImagePicker _picker = ip.ImagePicker(); @override Future pickImage({ImageSource source = ImageSource.gallery}) async { - return await _picker.pickImage(source: source); + return await _picker.pickImage(source: ip.ImageSource.values[source.index]); } @override diff --git a/lib/src/flimer_io.dart b/lib/src/flimer_io.dart index 0589141..8ba5d80 100644 --- a/lib/src/flimer_io.dart +++ b/lib/src/flimer_io.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:file_selector/file_selector.dart'; import 'package:flimer/flimer.dart'; -import 'package:image_picker/image_picker.dart'; +import 'package:image_picker/image_picker.dart' as ip; getFlimer() => FlimerIO(); @@ -22,9 +22,9 @@ class FlimerIO implements Flimer { Future pickImage({ImageSource source = ImageSource.gallery}) async { // Mobile platforms if (Platform.isAndroid || Platform.isIOS) { - final ImagePicker picker = ImagePicker(); + final ip.ImagePicker picker = ip.ImagePicker(); - return await picker.pickImage(source: source); + return await picker.pickImage(source: ip.ImageSource.values[source.index]); } // Desktop platforms @@ -39,7 +39,7 @@ class FlimerIO implements Flimer { Future?> pickImages() async { // Mobile platforms if (Platform.isAndroid || Platform.isIOS) { - final ImagePicker picker = ImagePicker(); + final ip.ImagePicker picker = ip.ImagePicker(); return await picker.pickMultiImage(); } diff --git a/lib/src/flimer_stub.dart b/lib/src/flimer_stub.dart index dee4d2d..efeeedf 100644 --- a/lib/src/flimer_stub.dart +++ b/lib/src/flimer_stub.dart @@ -1,5 +1,4 @@ import 'package:flimer/flimer.dart'; -import 'package:image_picker/image_picker.dart'; getFlimer() => FlimerStub(); diff --git a/lib/src/image_source.dart b/lib/src/image_source.dart new file mode 100644 index 0000000..b8332f2 --- /dev/null +++ b/lib/src/image_source.dart @@ -0,0 +1,8 @@ +/// Specifies the source where the picked image should come from. +enum ImageSource { + /// Opens up the device camera, letting the user to take a new picture. + camera, + + /// Opens the user's photo gallery. + gallery, +} diff --git a/macos/Classes/FlimerPlugin.swift b/macos/Classes/FlimerPlugin.swift new file mode 100644 index 0000000..19d1bf4 --- /dev/null +++ b/macos/Classes/FlimerPlugin.swift @@ -0,0 +1,14 @@ +import Cocoa +import FlutterMacOS + +public class FlimerPlugin: NSObject, FlutterPlugin { + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel(name: "flimer", binaryMessenger: registrar.messenger) + let instance = FlimerPlugin() + registrar.addMethodCallDelegate(instance, channel: channel) + } + + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + result(FlutterMethodNotImplemented) + } +} diff --git a/macos/flimer.podspec b/macos/flimer.podspec new file mode 100644 index 0000000..fd37cde --- /dev/null +++ b/macos/flimer.podspec @@ -0,0 +1,22 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. +# Run `pod lib lint flimer.podspec` to validate before publishing. +# +Pod::Spec.new do |s| + s.name = 'flimer' + s.version = '1.0.0' + s.summary = 'Flutter plugin for picking images on Mobile, Desktop and Web.' + s.description = <<-DESC +Flutter plugin for picking images on Mobile, Desktop and Web. + DESC + s.homepage = 'https://github.com/eyro-labs/flimer' + s.license = { :file => '../LICENSE' } + s.author = { 'Eyro Labs' => 'me@eyro.co.id' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.dependency 'FlutterMacOS' + + s.platform = :osx, '10.11' + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } + s.swift_version = '5.0' +end diff --git a/pubspec.lock b/pubspec.lock index f2e81bb..3d04f01 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -44,7 +44,7 @@ packages: source: hosted version: "1.15.0" cross_file: - dependency: transitive + dependency: "direct main" description: name: cross_file url: "https://pub.dartlang.org" diff --git a/pubspec.yaml b/pubspec.yaml index 096b807..971ad8b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: flutter: sdk: flutter + cross_file: ^0.3.1+4 image_picker: ^0.8.2 image_picker_platform_interface: ^2.2.0 file_selector: ^0.8.2 @@ -22,3 +23,24 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + +flutter: + plugin: + platforms: + android: + package: com.mesosfer.flimer + pluginClass: FlimerPlugin + ios: + pluginClass: FlimerPlugin + web: + pluginClass: FlimerHtml + fileName: src/flimer_html.dart + macos: + dartPluginClass: Flimer + pluginClass: none + windows: + dartPluginClass: Flimer + pluginClass: none + linux: + dartPluginClass: Flimer + pluginClass: none