paint method Null safety

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

Implementation

static void paint(Canvas c, String message, Map<int, Digit> digits,
    {required bool rightJustify}) {
  final Iterable<Digit> values = message.codeUnits.map(((ch) {
    final d = digits[ch];
    assert(d != null, 'No LCD character for ${String.fromCharCode(ch)}');
    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);
    }
  }
}