paint static method Null safety

void paint(
  1. Canvas c,
  2. String message,
  3. Map<int, Digit> digits,
  4. Color lcdForeground,
  5. {required bool rightJustify}
)

Implementation

static void paint(
    Canvas c, String message, Map<int, Digit> digits, Color lcdForeground,
    {required bool rightJustify}) {
  _paint.color = lcdForeground;
  final Iterable<Digit> values = message.codeUnits.map(((ch) {
    final d = digits[ch];
    assert(d != null,
        'No LCD character for ${String.fromCharCode(ch)} in $message');
    return d!;
  }));
  int width =
      values.fold(0, (int count, Digit d) => d.noWidth ? count : count + 1);
  if (rightJustify && width <= 11) {
    // Go one to the left of the first digit
    c.translate(_s.width * (10 - width), 0);
  } else {
    c.translate(0, Segments.h / 2);
    final double sf = 11.0 / max(width, 11);
    c.scale(sf);
    c.translate(-_s.width, -Segments.h / 2);
  }
  for (final Digit d in values) {
    if (!d.noWidth) {
      c.translate(_s.width, 0);
    }
    for (final Path p in d.segments) {
      c.drawPath(p, _paint);
    }
  }
}