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:
@@ -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}"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user