Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/share_plus/share_plus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 4.0.2

- Fix type mismatch on Android for some users
- Set min Flutter to 1.20.0 for all platforms
- Lower Android minSdkVersion to 22

## 4.0.1

- Hotfix dependencies
Expand Down
2 changes: 1 addition & 1 deletion packages/share_plus/share_plus/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ android {
compileSdkVersion 31

defaultConfig {
minSdkVersion 23
minSdkVersion 22
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,74 @@ import io.flutter.plugin.common.MethodChannel
import java.io.IOException

/** Handles the method calls for the plugin. */
internal class MethodCallHandler(private val share: Share, private val manager: ShareSuccessManager) : MethodChannel.MethodCallHandler {
internal class MethodCallHandler(
private val share: Share,
private val manager: ShareSuccessManager
) : MethodChannel.MethodCallHandler {

override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
when (call.method) {
"share" -> {
expectMapArguments(call)
// Android does not support showing the share sheet at a particular point on screen.
share.share(
call.argument<Any>("text") as String,
call.argument<Any>("subject") as String?,
false,
)
result.success(null)
}
"shareFiles" -> {
expectMapArguments(call)
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
when (call.method) {
"share" -> {
expectMapArguments(call)
// Android does not support showing the share sheet at a particular point on screen.
share.share(
call.argument<Any>("text") as String,
call.argument<Any>("subject") as String?,
false,
)
result.success(null)
}
"shareFiles" -> {
expectMapArguments(call)

// Android does not support showing the share sheet at a particular point on screen.
try {
share.shareFiles(
call.argument<List<String>>("paths")!!,
call.argument<List<String>?>("mimeTypes"),
call.argument<String?>("text"),
call.argument<String?>("subject"),
false,
)
result.success(null)
} catch (e: IOException) {
result.error(e.message, null, null)
}
}
"shareWithResult" -> {
expectMapArguments(call)
if(!manager.setCallback(result)) return
// Android does not support showing the share sheet at a particular point on screen.
try {
share.shareFiles(
call.argument<List<String>>("paths")!!,
call.argument<List<String>?>("mimeTypes"),
call.argument<String?>("text"),
call.argument<String?>("subject"),
false,
)
result.success(null)
} catch (e: IOException) {
result.error("Share failed", e.message, null)
}
}
"shareWithResult" -> {
expectMapArguments(call)
Copy link
Contributor

@ekuleshov ekuleshov Mar 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could these *withResults(..) methods extended with check like this?

if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
  result.notImplemented()
else ...

Then it won't be necessary to bump the minSdkVersion version for Android platform and it could be kept at the level supported in 3.x version of plugin.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. If anyone can submit a separated PR with a that change, that would be awesome!

if (!manager.setCallback(result)) return

// Android does not support showing the share sheet at a particular point on screen.
share.share(
call.argument<Any>("text") as String,
call.argument<Any>("subject") as String?,
true,
)
}
"shareFilesWithResult" -> {
expectMapArguments(call)
if(!manager.setCallback(result)) return
// Android does not support showing the share sheet at a particular point on screen.
share.share(
call.argument<Any>("text") as String,
call.argument<Any>("subject") as String?,
true,
)
}
"shareFilesWithResult" -> {
expectMapArguments(call)
if (!manager.setCallback(result)) return

// Android does not support showing the share sheet at a particular point on screen.
try {
share.shareFiles(
call.argument<List<String>>("paths")!!,
call.argument<List<String>?>("mimeTypes"),
call.argument<String?>("text"),
call.argument<String?>("subject"),
true,
)
} catch (e: IOException) {
result.error(e.message, null, null)
// Android does not support showing the share sheet at a particular point on screen.
try {
share.shareFiles(
call.argument<List<String>>("paths")!!,
call.argument<List<String>?>("mimeTypes"),
call.argument<String?>("text"),
call.argument<String?>("subject"),
true,
)
} catch (e: IOException) {
result.error("Share failed", e.message, null)
}
}
else -> result.notImplemented()
}
}
else -> result.notImplemented()
}
}

@Throws(IllegalArgumentException::class)
private fun expectMapArguments(call: MethodCall) {
require(call.arguments is Map<*, *>) { "Map arguments expected" }
}
@Throws(IllegalArgumentException::class)
private fun expectMapArguments(call: MethodCall) {
require(call.arguments is Map<*, *>) { "Map arguments expected" }
}
}
Loading