Skip to content

Commit

Permalink
1.尝试更新插件
Browse files Browse the repository at this point in the history
  • Loading branch information
mofada committed Jun 3, 2020
1 parent 3f4b2f0 commit 47c2a4f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions android/src/main/kotlin/cn/mofada/update_app/UpdateAppPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package cn.mofada.update_app

import android.content.Context
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

class UpdateAppPlugin(private val context: Context) : MethodCallHandler {
class UpdateAppPlugin : FlutterPlugin, MethodCallHandler {
private lateinit var channel: MethodChannel

private lateinit var context: Context

companion object {
@JvmStatic
fun registerWith(registrar: Registrar) {
val channel = MethodChannel(registrar.messenger(), "cn.mofada.cn/update_app")
channel.setMethodCallHandler(UpdateAppPlugin(registrar.context()))
val updateAppPlugin = UpdateAppPlugin()
channel.setMethodCallHandler(updateAppPlugin)
//初始化上下文
updateAppPlugin.context = registrar.context()
}
}

Expand All @@ -23,6 +31,16 @@ class UpdateAppPlugin(private val context: Context) : MethodCallHandler {
else -> result.notImplemented()
}
}

override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.flutterEngine.dartExecutor, "cn.mofada.cn/update_app")
context = flutterPluginBinding.applicationContext
channel.setMethodCallHandler(this)
}

override fun onDetachedFromEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}
}


Expand Down
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[],"android":[],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"update_app","dependencies":[]}],"date_created":"2020-06-03 20:31:51.352880","version":"1.17.2"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[],"android":[],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"update_app","dependencies":[]}],"date_created":"2020-06-03 21:12:52.035828","version":"1.17.2"}

0 comments on commit 47c2a4f

Please sign in to comment.