'Filter in calendarView

How can I filter the list to the selected date of the calendarView My error in in line *emit(it)

private fun getFilmsDbFlow(resultDb: ResultDb): Flow<ResultsTarea> = flow<ResultsTarea> {
    val date : Calendar = Calendar.getInstance()
    val sdf = SimpleDateFormat("dd - MM - yyyy")
    var curDate = sdf.format(date.getTime())

    mBinding.calendarView.setOnDateChangeListener(CalendarView.OnDateChangeListener { view, year, month, dayOfMonth ->
        curDate =
            dayOfMonth.toString() + " - " + month.plus(1) + " - " + year

        val films = resultDb.resultsTareas
            .filter { it.fecha == curDate }

        films.forEach {
            emit(it)
        }
    })
    }.flowOn(Dispatchers.IO)

private fun getAllFilmsDb(){
    lifecycleScope.launch {
        getFilmsDbFlow(getFilmsDb()).collect {
            mAdapter.add(it)
            }
        }        
}

my error is:

Suspension functions can be called only within coroutine body


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source