bytesToHex function

String bytesToHex(
  1. List<int> bytes, {
  2. bool include0x = false,
  3. int? forcePadLength,
  4. bool padToEven = false,
})

Legacy bytesToHex compatibility

Implementation

String bytesToHex(
  List<int> bytes, {
  bool include0x = false,
  int? forcePadLength,
  bool padToEven = false,
}) {
  var encoded = HexUtils.encode(Uint8List.fromList(bytes));
  if (encoded.startsWith('0x')) encoded = encoded.substring(2);
  if (padToEven && encoded.length % 2 != 0) encoded = '0$encoded';
  if (forcePadLength != null) encoded = encoded.padLeft(forcePadLength, '0');
  return include0x ? '0x$encoded' : encoded;
}