Home > Net >  Why items captured object giving me No reference found in Compose
Why items captured object giving me No reference found in Compose

Time:11-29

I've a data class:

data class Feed_Status(val img:Int, val name_id: String)

I've a class:

class Feed_helper {

    fun Image_getter(): List<() -> Feed_Status> {

        val Images = listOf {
            Feed_Status(R.drawable.image_demo1, "name1")
            Feed_Status(R.drawable.image_demo2, "name2")
            Feed_Status(R.drawable.image_demo3, "name3")
            Feed_Status(R.drawable.image_demo4, "name4")
            Feed_Status(R.drawable.image_demo5, "name5")
            Feed_Status(R.drawable.image_demo6, "name6")
            Feed_Status(R.drawable.image_demo7, "name7")
            Feed_Status(R.drawable.image_demo8, "name8")
            Feed_Status(R.drawable.image_demo9, "name9")
            Feed_Status(R.drawable.image_demo10, "name10")
            Feed_Status(R.drawable.image_demo11, "name11")
            Feed_Status(R.drawable.image_demo12, "name12")
            Feed_Status(R.drawable.image_demo13, "name13")
            Feed_Status(R.drawable.image_demo14, "name14")
            Feed_Status(R.drawable.image_demo15, "name15")
            Feed_Status(R.drawable.image_demo16, "name16")
            Feed_Status(R.drawable.image_demo17, "name17")
            Feed_Status(R.drawable.image_demo18, "name18")
            Feed_Status(R.drawable.image_demo19, "name19")
            Feed_Status(R.drawable.image_demo20, "name20")
            Feed_Status(R.drawable.image_demo21, "name21")
            Feed_Status(R.drawable.image_demo22, "name22")
            Feed_Status(R.drawable.image_demo23, "name23")
            Feed_Status(R.drawable.image_demo24, "name24")
            Feed_Status(R.drawable.image_demo25, "name25")
            Feed_Status(R.drawable.image_demo25, "name26")
        }

        return Images
    }
}

through which I'm calling items() in lazyRow

@Composable
fun feed() {

    LazyColumn(
        reverseLayout = false,
        modifier = Modifier
            .fillMaxSize(),
        userScrollEnabled = true
    ) {
          // Status(es)
         item {
            LazyRow(
                reverseLayout = false,
                modifier = Modifier
                    .fillMaxWidth()
                    .height(100.dp),
                horizontalArrangement = Arrangement.SpaceBetween,
                userScrollEnabled = true
            ) {
                 val statuses = Feed_helper().Image_getter()
                 items(statuses) { status ->
                    Column(
                        verticalArrangement = Arrangement.Center,
                        modifier = Modifier
                                .width(80.dp)

                    ) {


                        Card(
                            shape = CircleShape,
                            modifier = Modifier
                                .padding(8.dp)
                                .size(64.dp)
                        ) {


                            Image(
                                painterResource(id = status.img),
                                contentDescription = status.name_id   "'s status",
                                contentScale = ContentScale.Crop
                            )

                        }

                        Text(
                            text = status.name_id,
                            modifier = Modifier.fillMaxWidth(),
                            textAlign = TextAlign.Center,
                        )

                    }

                }

            }

        }

    }

}

But whenever I'm calling element from statuses through statuses in items() it is giving me Reference Not found!

Callers:

painterResource(id = status.img) in Image()

contentDescription = status.name_id "'s status" in Image()

text = status.name_id in Text

All callers are in items(statuses){ status ->

I've been trying to solve this for hours. So any help will be very apreciated.

If you find any typo please update it or tell me to fix.

PS: This is my first time here and I have an almost zero experience on android development and Kotlin. I developed terminal apps and worked on ML kinda work in Python, C , C. So I may need more information in explanation. I started learning Android Development a week ago only.

Edit: You can ask me any more information.

Peace

CodePudding user response:

Change the return type of Image_getter to List<Feed_status> instead of it having a type of lambda, and change the braces to parenthesis when you declare the list of them.

class Feed_helper {

    fun Image_getter(): List<Feed_Status> { // change it to this instead of type of lambda `() -> Feed_status`

        val Images = listOf ( // change it to this instead of braces
           ...
        )

        return Images
    }
}

and import

import androidx.compose.foundation.lazy.items
  • Related