getCharLength method

dynamic getCharLength(
  1. dynamic param
)

Implementation

getCharLength(param) {
  myLogAll('getCharLength');
  var value = '';
  bool needI10n = true;
  if (param is Map) {
    value = param[gLabel] ?? param[gValue];
    needI10n = param[gNeedi10n] ?? true;
  } else {
    value = (param ?? '').toString();
  }

  String showValue = needI10n ? getSCurrent(value) : value;
  showValue = showValue.replaceAll(' ', '_');
  final textSpan = TextSpan(
    text: showValue,
    style: TextStyle(fontSize: getFontSize(param) ?? 12.0),
  );

  final tp = TextPainter(
      text: textSpan,
      textAlign: TextAlign.left,
      textDirection: ui.TextDirection.ltr);
  tp.layout();
  return tp.width;

  /*var lanCode = gEn;
  if (param[gNeedi10n] ?? true) {
    lanCode = _locale;
  }
  print('text width: ${tp.width}');

  String showValue = (param[gNeedi10n] ?? true) ? getSCurrent(value) : value;

  return showValue.length * ((lanCode == gEn) ? 9.0 : 20.0);*/
}