ConfigColor.fromHex constructor

ConfigColor.fromHex({
  1. required String hex,
  2. required String name,
})

A Color created from a hexadecimal value. Accepted formats include:

  • 0ff6002ee
  • #6002ee
  • 6002ee

And is case insensitive. A Color that is adapted from a configuration.

Implementation

factory ConfigColor.fromHex({
  required String hex,
  required String name,
}) {
  assert(name.isNotEmpty, '[name] cannot be empty.');
  assert(hex.length > 5, '[hex.length] should be at least 6.');

  hex = hex.substring(hex.length - 6, hex.length);

  return ConfigColor(
    red: getInt(hex.substring(0, 2)),
    green: getInt(hex.substring(2, 4)),
    blue: getInt(hex.substring(4, 6)),
    name: name,
  );
}