user10625391
user10625391

Reputation: 317

my model information is not showing jetpack compose

Im using kotling jetpack compose and have the next problem,

when I compile the project there's is no error but my components doesn't show on the screen. funny thing is that the mistake is on the response modules because when i comment this part @field:SerializedName("style") val Style: Style, the project compiles ight and show everything i need except the style that i need. Im getting the style from an api this is the api response

 {
    "isWeekTopic": false,
    "_id": "62d739f65a4f2db1b81b5192",
    "topicNumber": "1",
    "title": "Números naturales",
    "thumbnail": "https://www.example.com",
    "relatedSkillsId": [
        "62c12752d9de3e63d7cd0a78"
    ],
    "relatedSubSkillsId": [
        "62d73a8c5a4f2db1b81b5194"
    ],
    "style": {
        "mainColor": "#f2f2f2",
        "secondColor": "#f2f2f2",
        "image": "https://www.example.com"
    },
    "createdAt": "2018-01-01T00:00:00.000Z",
    "updatedAt": "2018-01-01T00:00:00.000Z",
    "assetsStreak": {
        "VIDEO": 2,
        "STORY": 0,
        "VIDEOGAME": 2,
        "INFOGRAPHIC": 2,
        "EXPLANATION": 0,
        "STEPBYSTEP": 2
    },
    "skillPercent": 60
},

and this is my remote response model

@Parcelize
data class TopicsItemRemoteResponseModel(
    @field:SerializedName("_id")
    val topicsId: String = "",
    @field:SerializedName("title")
    val title: String = "",
    @field:SerializedName("skillNumber")
    val skillNumber: Int = 0,
    @field:SerializedName("skillPercent")
    val skillPercent: Int = 10,
    @field:SerializedName("thumbnail")
    val thumbnail: String = "",
    @field:SerializedName("createdAt")
    val createdAt: String = "",
    @field:SerializedName("updatedAt")
    val updatedAt: String = "",
    @field:SerializedName("isWeekTopic")
    val isWeekTopic: Boolean = false,
    @field:SerializedName("relatedSkillsId")
    val relatedSkillsId: List<String> = listOf(),
    @field:SerializedName("relatedSubSkillsId")
    val relatedSubSkillsId: List<String> = listOf(),
    @field:SerializedName("style")
    val Style: Style,
) : Parcelable {
    companion object {
        fun mapListFromRemoteToDomainModel(
            remoteList: List<TopicsItemRemoteResponseModel>): List<TopicsItemResponseModel> {
            val topics = mutableListOf<TopicsItemResponseModel>()
            remoteList.forEach { topicsRemoteResponseItem ->
                topics.add(
                    mapFromRemoteToDomainModel(topicsRemoteResponseItem)
                )
            }
            return topics
        }
        private fun mapFromRemoteToDomainModel(
            topicsRemoteResponseItem: TopicsItemRemoteResponseModel
        ): TopicsItemResponseModel = with(topicsRemoteResponseItem) {
            return TopicsItemResponseModel(
                topicsId = topicsId,
                skillNumber = skillNumber,
                title = title,
                skillPercent = skillPercent,
                thumbnail = thumbnail,
                createdAt = createdAt,
                updatedAt = updatedAt,
                isWeekTopic = isWeekTopic,
                relatedSkillsId = relatedSkillsId,
                relatedSubSkillsId = relatedSubSkillsId,
                Style = Style
            )
        }
    }
}
@Parcelize
    data class Style(
        @field:SerializedName("mainColor")
        val mainColor: Color,
        @field:SerializedName("secondColor")
        val secondColor: Color,
        @field:SerializedName("image")
        val image: String = "",

    ) : Parcelable {
    fun mapFromRemoteToDomainModel():Style {
        return Style(
            mainColor = mainColor,
            secondColor = secondColor,
            image = image
        )
    }
}

i need to acces to that style but for some reason when i put it on the model nothing shows on the app, but if i delete it the app works, any clue?

Upvotes: 0

Views: 63

Answers (1)

Ot&#225;vio Moreira
Ot&#225;vio Moreira

Reputation: 76

Try extract Style data class to out of TopicsItemRemoteResponseModel data class. Also, the hexacolor on two first params for the JSON are just Strings. You can change the type to String e convert to Color type later on your code.

Upvotes: 1

Related Questions