hexFixLength function

String hexFixLength(
  1. String value, [
  2. int bitLength = -1,
  3. bool withPadding = false
])

Implementation

String hexFixLength(String value,
    [int bitLength = -1, bool withPadding = false]) {
  var strLength = (bitLength / 4).ceil();
  var hexLength = strLength + 2;
  // ignore: prefer_typing_uninitialized_variables
  var beforeAdd;

  if ((bitLength == -1 ||
      value.length == hexLength ||
      (!withPadding && value.length < hexLength))) {
    beforeAdd = hexStripPrefix(value);
  } else {
    if ((value.length > hexLength)) {
      var stripped = hexStripPrefix(value);
      beforeAdd = stripped.substring(stripped.length - 1 * strLength);
    } else {
      var stripped2 = "${'0' * strLength}${hexStripPrefix(value)}";
      beforeAdd = stripped2.substring(stripped2.length - 1 * strLength);
    }
  }
  return hexAddPrefix(beforeAdd);
}