Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

color blindness

color blindness

every app has colors. how to make sure they are accessible? how to avoid accessibility issues as other people in the same project start to change the color scheme? this is a flutter plugin that can:

  1. change the whole theme, by wrapping a colorscheme with colorblindnesscolorscheme().
  2. be used in ci tests, with colorblindnessassertcontrast().
  3. be used to modify a single color.

the main idea is for you to (temporarily) wrap your colorscheme() into a colorblindnesscolorscheme() with a colorblindnesstype as the secondary parameter.
doing so, it will simulate color blindness by modifying all colorscheme colors.
then, you may change the type parameter and hot refresh/restart the app to see how it looks under different eyes.

the interactive sample allows you to see how it works:

try_here

usage

in the pubspec.yaml of your flutter project, add the following dependency:

pub package

dependencies:
  color_blindness: ^version

color scheme

in your project, just wrap the colorscheme.dark(...) with colorblindnesscolorscheme().

import 'package:random_colorscheme/color_blindness_color_scheme.dart';

theme(
  data: themedata(
    colorscheme: colorblindnesscolorscheme(colorscheme.dark(), colorblindnesstype.tritanopia),
  ),
  child: myapp(),
)

ci

you can add a test to make sure the colorscheme is always accessible.
the second parameter is the wcag minimum threshold, which is usually at least 4.5.

colorscheme = colorscheme.light(
  primary: const color(0xff9f0042),
  secondary: const color(0xff1e6100),
);
expect(() => colorblindnessassertcontrast(colorscheme, 4.0), returnsnormally);

single color

you can either use colorblindness() with colorblindnesstype as the secondary parameter, or call the methods individually.

const primary = const color(0xff9f0042);
// indirect way
colorblindness(primary, colorblindnesstype.tritanopia);

// direct way
tritanopia(primary);

reasoning

this started in my color studio project. there, you can preview different color blindness in different themes.
however, i saw the possibility of contribution for those already using colorscheme in an existing app.
similar to randomcolorscheme, this may reach deeper places than color studio ever will.
also, there were zero packages in pub.dev related to color blindness, so this was the first one.
the color blindness calculation was retrieved from colorblinds project.

function listing

  • colorblindnesscolorscheme(scheme: colorscheme, type: colorblindnesstype): colorscheme
  • colorblindnessassertcontrast(scheme: colorscheme, minthreshold: double = 4.5)
  • colorblindness(color: color, type: colorblindnesstype): color
  • protanomaly(color: color): color
  • deuteranomaly(color: color): color
  • tritanomaly(color: color): color
  • protanopia(color: color): color
  • deuteranopia(color: color): color
  • tritanopia(color: color): color
  • achromatopsia(color: color): color
  • achromatomaly(color: color): color

enum colorblindnesstype { none, protanomaly, deuteranomaly, tritanomaly, protanopia, deuteranopia, tritanopia, achromatopsia, achromatomaly }


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.