【发布时间】:2021-02-02 21:53:40
【问题描述】:
我已经尝试了所有能找到的咒语,但 viewModel 使用仍然存在问题。
这里是有问题的代码:
class MainActivity: FlutterActivity(), OnSneakerClickListener, OnSneakerDismissListener {
private val httpclient = OkHttpClient()
val stripe = Stripe(this, "pk_test_yadayadayada")
private val viewModel: StripeIntentViewModel by viewModels() //<--dragons be here
当我手动输入“import androidx.activity.viewModels”时,它显示为“未使用的导入指令”。
我的模块 build.gradle 文件如下所示:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'checkstyle'
id 'org.jetbrains.kotlin.plugin.parcelize'
}
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
...
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$androidLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$androidLifecycleVersion"
implementation "com.google.android.material:material:$materialVersion"
implementation "androidx.fragment:fragment-ktx:$fragmentVersion"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.activity:activity-ktx:1.1.0"
implementation "androidx.fragment:fragment-ktx:1.2.5"
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.activity:activity-ktx:1.2.0-rc01"
有什么遗漏吗?
【问题讨论】:
标签: android kotlin android-viewmodel