Search code examples
androidkotlinandroid-databindingkotlin-stateflow

Cannot find a setter for that accepts parameter type 'kotlinx.coroutines.flow.MutableStateFlow' DataBinding Android


I'm using data-binding to handle MutableStateFlow in my ViewModel

  private val _searchSkeleton = MutableStateFlow(View.GONE)
  val searchSkeletonVis = _searchSkeleton

Here's my usage in the XML file

  app:viewVisibility="@{viewModel.searchSkeletonVis}"

And this is my BindingAdapter

@BindingAdapter("app:viewVisibility")
fun bindViewVisibility(
    @NonNull view: View,
    @NonNull visibility: Int,
) {
    view.visibility = visibility
}

and it gives me this error

Cannot find a setter for that accepts parameter type 'kotlinx.coroutines.flow.MutableStateFlow'

But when I use LiveData it's working fine!


Solution

  • Stateflow is only supported in Android Gradle Plugin version 7.0.0-alpha04 or higher as per the documentation.