tryFromUtf8 function

String? tryFromUtf8(
  1. List<int> input, {
  2. UTF8Codec codec = UTF8Codec.standard,
})

Converts a UTF-8 octet sequence to code points, returning null instead of throwing when the input is not a valid UTF-8 octet sequence.

This is the non-throwing counterpart of fromUtf8. See fromUtf8 for the meaning of codec.

Implementation

String? tryFromUtf8(
  List<int> input, {
  UTF8Codec codec = UTF8Codec.standard,
}) {
  try {
    return fromUtf8(input, codec: codec);
  } on FormatException {
    return null;
  }
}