toARGB32 method

  1. @override
int toARGB32()
override

Returns a 32-bit value representing this color.

The returned value is compatible with the default constructor (Color.new) but does not guarantee to result in the same color due to imprecisions in numeric conversions.

Unlike accessing the floating point equivalent channels individually (a, r, g, b), this method is intentionally lossy, and scales each channel using (channel * 255.0).round() & 0xff.

While useful for storing a 32-bit integer value, prefer accessing the individual channels (and storing the double equivalent) where higher precision is required.

The bits are assigned as follows:

  • Bits 24-31 represents the a channel as an 8-bit unsigned integer.
  • Bits 16-23 represents the r channel as an 8-bit unsigned integer.
  • Bits 8-15 represents the g channel as an 8-bit unsigned integer.
  • Bits 0-7 represents the b channel as an 8-bit unsigned integer.

Warning

The value returned by this getter implicitly converts floating-point component values (such as 0.5) into their 8-bit equivalent by using the toARGB32 method; the returned value is not guaranteed to be stable across different platforms or executions due to the complexity of floating-point math.

Implementation

@override
// TODO(matanl): Remove once https://github.com/flutter/engine/pull/56329 lands in the framework.
// ignore: override_on_non_overriding_member, public_member_api_docs
int toARGB32() => value;