Hello all, How to save `Color` to `room db` in Jet...
# compose
s
Hello all, How to save
Color
to
room db
in Jetpack Compose?. I’m trying to save an Article to room db (One of the params is
Compose Color
). Currently it shows error like to Use
TypeConverter
for
color
field to save the data. How to achieve this?. Below I’ve attached my Model class.
s
You can use type converters so room can convert your
Color
to and from
Long
(or
Int
) to store or retrieve from the db
s
@Se7eN I did that already still I got this error 👇
error: Class is referenced as a converter but it does not have any converter methods.
ColorConverters Class 👇
Copy code
class ColorConverters {

    @TypeConverter
    fun fromColor(color: Color) : Int? {
     return color.toArgb()
    }

    @TypeConverter
    fun toColor(color:Int) : Color {
        return Color(color)
    }
}
a
I believe Room compiler doesn't support inline classes (value classes).
Found an issue.
👍 2
s
Guess you're gonna have to store an
Int
for now and create an extension
Source.color
for
Color
. Or maybe use
android.graphics.Color
1
589 Views