hexToBytes function

Uint8List hexToBytes(
  1. String hexStr
)

Convert a hexadecimal string to a Uint8List. This function takes a hexadecimal string 'hexStr', removes the '0x' prefix if present, and converts it into a Uint8List containing the corresponding byte values. It returns the Uint8List representation of the hexadecimal string.

Implementation

Uint8List hexToBytes(String hexStr) {
  /// Remove the '0x' prefix from the hexadecimal string.
  final bytes = hex.decode(strip0x(hexStr));

  /// Check if the result is already a Uint8List.
  if (bytes is Uint8List) {
    return bytes;
  }

  /// If not, create a new Uint8List from the list of bytes.
  return Uint8List.fromList(bytes);
}