title: Jetpack Compose – Which dependency do I need to use to be able to use state delegates?
body: <p>I have a compile-time error with the samples provided in the code-labs.</p>
  <p>This is the ViewModel</p>
  <pre class="lang-kotlin prettyprint-override"><code>class VM : ViewModel() {
       val isVisible = MutableStateFlow(true).asStateFlow()
  }
  </code></pre>
  <p>This is what I'd like to write:</p>
  <pre class="lang-kotlin prettyprint-override"><code>@Composable
  fun Whatever(vm: VM = viewModel()) {
      val isVisible by vm.isVisible.collectAsState(true)
      // Use is visible here
  }
  </code></pre>
  <p>But it yields to the following error:</p>
  <blockquote>
  <p>Type 'State&lt;TypeVariable(R)&gt;' has no method 'getValue(Nothing?, KProperty&lt;*&gt;)' and thus it cannot serve as a delegate</p>
  </blockquote>
  <p>Which is really strange because I can use it like so:</p>
  <pre class="lang-kotlin prettyprint-override"><code>@Composable
  fun Whatever(vm: VM = viewModel()) {
      val isVisible = vm.isVisible.collectAsState(true)
      if(isVisible.value) { … }
  }
  </code></pre>
  <p>What dependency do I need to bring in to make the delegate work?</p>
  <p>Here are my dependencies: and <code>compose_version = 1.0.0-beta01</code></p>
  <pre><code>dependencies {
      // LiveData
      implementation &quot;androidx.lifecycle:lifecycle-livedata-ktx:2.3.0&quot;
      implementation 'androidx.core:core-ktx:1.3.2'
      implementation 'androidx.appcompat:appcompat:1.2.0'
      implementation 'com.google.android.material:material:1.3.0'
  
      implementation &quot;androidx.activity:activity-compose:1.3.0-alpha03&quot;
      implementation &quot;androidx.compose.runtime:runtime:$compose_version&quot;
      implementation &quot;androidx.compose.ui:ui:$compose_version&quot;
      implementation &quot;androidx.compose.foundation:foundation-layout:$compose_version&quot;
      implementation &quot;androidx.compose.material:material:$compose_version&quot;
      implementation &quot;androidx.compose.material:material-icons-extended:$compose_version&quot;
      implementation &quot;androidx.compose.foundation:foundation:$compose_version&quot;
      implementation &quot;androidx.compose.animation:animation:$compose_version&quot;
      implementation &quot;androidx.compose.ui:ui-tooling:$compose_version&quot;
      implementation &quot;androidx.compose.runtime:runtime-livedata:$compose_version&quot;
      implementation &quot;androidx.compose.runtime:runtime:$compose_version&quot;
      implementation &quot;androidx.compose.ui:ui:$compose_version&quot;
      implementation &quot;androidx.compose.ui:ui-tooling:$compose_version&quot;
  
      implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0'
  
      // Kotlin coroutines
      implementation &quot;org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version&quot;
  
      implementation 'androidx.appcompat:appcompat:1.3.0-beta01'
      implementation 'androidx.activity:activity-ktx:1.2.0'
      implementation 'androidx.core:core-ktx:1.5.0-beta02'
      implementation &quot;androidx.activity:activity-compose:1.3.0-alpha03&quot;
  
      implementation &quot;androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0&quot;
      implementation &quot;androidx.lifecycle:lifecycle-livedata-ktx:2.3.0&quot;
      implementation &quot;androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha02&quot;
  
      androidTestImplementation 'androidx.test:rules:1.3.0'
      androidTestImplementation 'androidx.test:runner:1.3.0'
      androidTestImplementation &quot;androidx.compose.ui:ui-test:$compose_version&quot;
      androidTestImplementation &quot;androidx.compose.ui:ui-test-junit4:$compose_version&quot;
  }
  </code></pre>