1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-11 15:28:44 +00:00

Tidying up add-to-app samples (#160)

This commit is contained in:
Andrew Brogdon
2019-11-05 09:21:39 -08:00
committed by GitHub
parent e184a46ce6
commit 8155d8a777
17 changed files with 146 additions and 38 deletions

View File

@@ -11,7 +11,7 @@ import androidx.appcompat.app.AppCompatActivity
import io.flutter.embedding.android.FlutterActivity
class MainActivity : AppCompatActivity() {
private var counterLabel: TextView? = null
private lateinit var counterLabel: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -32,6 +32,6 @@ class MainActivity : AppCompatActivity() {
override fun onResume() {
super.onResume()
val app = application as MyApplication
counterLabel?.text = "Current count: ${app.count}"
counterLabel.text = "Current count: ${app.count}"
}
}

View File

@@ -15,7 +15,7 @@ const val ENGINE_ID = "1"
class MyApplication : Application() {
var count = 0
private var channel: MethodChannel? = null
private lateinit var channel: MethodChannel
override fun onCreate() {
super.onCreate()
@@ -31,7 +31,7 @@ class MyApplication : Application() {
channel = MethodChannel(flutterEngine.dartExecutor, "dev.flutter.example/counter")
channel?.setMethodCallHandler { call, _ ->
channel.setMethodCallHandler { call, _ ->
when (call.method) {
"incrementCounter" -> {
count++
@@ -45,6 +45,6 @@ class MyApplication : Application() {
}
private fun reportCounter() {
channel?.invokeMethod("reportCounter", count)
channel.invokeMethod("reportCounter", count)
}
}