Type ‘MutableState<Boolean>’ has no method ‘setValue(Nothing?, KProperty<*>, Boolean)’ and thus it cannot serve as a delegate for var (read-write property)
by 키워드를 통해 위임할 경우 MutableState는 getValue
와 setValue
가 필요하다. MutableState를 mutableStateOf 를 사용할 경우
import androidx.compose.runtime.mutableStateOf
위의 import 가 추가되지만, mutableStateOf 에는 MutableState를 위한 getValue
, setValue
가 포함되지 않는다. 두 함수는 별도의 파일에 확장함수로 구현되어있기 때문이다. 따라서 아래의 두 import를 수동으로 추가해주면 된다. (Android Studio에서 auto-suggest 되지 않기 때문에)
import androidx.compose.runtime.setValue
import androidx.compose.runtime.getValue
참고