tryDecode static method

String? tryDecode(
  1. List<int>? value, {
  2. StringEncoding type = StringEncoding.utf8,
  3. bool allowInvalidOrMalformed = false,
})

Decodes a list of bytes value into a string using the specified type if possible.

The type parameter determines the decoding type to use, with UTF-8 being the default. Returns the decoded string.

Implementation

static String? tryDecode(List<int>? value,
    {StringEncoding type = StringEncoding.utf8,
    bool allowInvalidOrMalformed = false}) {
  if (value == null) return null;
  try {
    return decode(value,
        type: type, allowInvalidOrMalformed: allowInvalidOrMalformed);
  } catch (e) {
    return null;
  }
}