Skip to content

Commit

Permalink
Fix pana (#1)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alann-maulana authored Aug 1, 2021
1 parent c2a6142 commit 628e986
Show file tree
Hide file tree
Showing 25 changed files with 281 additions and 15 deletions.
8 changes: 8 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
40 changes: 40 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 3 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
5 changes: 5 additions & 0 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'flimer'
3 changes: 3 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mesosfer.flimer">
</manifest>
32 changes: 32 additions & 0 deletions android/src/main/kotlin/com/mesosfer/flimer/FlimerPlugin.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
6 changes: 6 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 6 additions & 0 deletions example/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.1"
version: "1.0.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down
37 changes: 37 additions & 0 deletions ios/.gitignore
Original file line number Diff line number Diff line change
@@ -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
Empty file added ios/Assets/.gitkeep
Empty file.
4 changes: 4 additions & 0 deletions ios/Classes/FlimerPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import <Flutter/Flutter.h>

@interface FlimerPlugin : NSObject<FlutterPlugin>
@end
15 changes: 15 additions & 0 deletions ios/Classes/FlimerPlugin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#import "FlimerPlugin.h"
#if __has_include(<flimer/flimer-Swift.h>)
#import <flimer/flimer-Swift.h>
#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<FlutterPluginRegistrar>*)registrar {
[SwiftFlimerPlugin registerWithRegistrar:registrar];
}
@end
14 changes: 14 additions & 0 deletions ios/Classes/SwiftFlimerPlugin.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
23 changes: 23 additions & 0 deletions ios/flimer.podspec
Original file line number Diff line number Diff line change
@@ -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' => '[email protected]' }
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
11 changes: 6 additions & 5 deletions lib/flimer.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();

Expand Down
9 changes: 6 additions & 3 deletions lib/src/flimer_html.dart
Original file line number Diff line number Diff line change
@@ -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<XFile?> pickImage({ImageSource source = ImageSource.gallery}) async {
return await _picker.pickImage(source: source);
return await _picker.pickImage(source: ip.ImageSource.values[source.index]);
}

@override
Expand Down
8 changes: 4 additions & 4 deletions lib/src/flimer_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -22,9 +22,9 @@ class FlimerIO implements Flimer {
Future<XFile?> 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
Expand All @@ -39,7 +39,7 @@ class FlimerIO implements Flimer {
Future<List<XFile>?> pickImages() async {
// Mobile platforms
if (Platform.isAndroid || Platform.isIOS) {
final ImagePicker picker = ImagePicker();
final ip.ImagePicker picker = ip.ImagePicker();

return await picker.pickMultiImage();
}
Expand Down
1 change: 0 additions & 1 deletion lib/src/flimer_stub.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flimer/flimer.dart';
import 'package:image_picker/image_picker.dart';

getFlimer() => FlimerStub();

Expand Down
8 changes: 8 additions & 0 deletions lib/src/image_source.dart
Original file line number Diff line number Diff line change
@@ -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,
}
14 changes: 14 additions & 0 deletions macos/Classes/FlimerPlugin.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
22 changes: 22 additions & 0 deletions macos/flimer.podspec
Original file line number Diff line number Diff line change
@@ -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' => '[email protected]' }
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
Loading

0 comments on commit 628e986

Please sign in to comment.