Some kotlin cosmetic tweaks (#157)

pull/158/head
xster 5 years ago committed by GitHub
parent a29853144b
commit 57759009aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,8 +30,8 @@ dependencies {
implementation project(':flutter') implementation project(':flutter')
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.0.2' implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0' androidTestImplementation 'androidx.test.ext:junit:1.1.0'

@ -11,14 +11,13 @@ import androidx.appcompat.app.AppCompatActivity
import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.android.FlutterActivity
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
private var counterLabel: TextView? = null private lateinit var counterLabel: TextView
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
counterLabel = findViewById(R.id.counter_label) counterLabel = findViewById(R.id.counter_label)
val button = findViewById<Button>(R.id.launch_button) val button = findViewById<Button>(R.id.launch_button)
button.setOnClickListener { button.setOnClickListener {
@ -32,6 +31,6 @@ class MainActivity : AppCompatActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
val app = application as MyApplication val app = application as MyApplication
counterLabel?.text = "Current count: ${app.count}" counterLabel.text = "Current count: ${app.count}"
} }
} }

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

Loading…
Cancel
Save