getTextWidth static method

int getTextWidth(
  1. String text,
  2. int charSpacing
)

Implementation

static int getTextWidth(String text, int charSpacing) {
  int width = 0;
  for (int i = 0; i < text.length; i++) {
    int charCode = text.codeUnitAt(i);
    width += charWidthMapping[charCode] ?? 25;
    width += charSpacing;
  }
  // if there's more than one character we probably should trim the extra charSpacing at the end
  return width == 0 ? 0 : width - charSpacing;
}