ColorConverter class
A JSON converter for Flutter's Color class.
This converter serializes Color objects to JSON as a 32-bit ARGB integer, and deserializes integers back to Color objects. The integer representation includes alpha, red, green, and blue channels in ARGB format.
Example JSON representation:
4294901760 // 0xFFFF0000 - Red color
Usage with json_serializable:
@JsonSerializable()
class MyClass {
@ColorConverter()
final Color backgroundColor;
MyClass(this.backgroundColor);
}
Note: The integer format preserves the full ARGB color information including opacity, making it suitable for complete color serialization.
See also:
- Color, the Flutter class representing colors
- Color.toARGB32, the method used for serialization
Constructors
- ColorConverter()
-
Creates a const instance of ColorConverter.
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
fromJson(
int json) → Color - Converts a 32-bit ARGB integer to a Color object.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
Color color) → int - Converts a Color object to a 32-bit ARGB integer.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited