In Flutter, utf8.decode(bytes) from dart:convert converts a UTF-8 byte list into a Dart string and throws a FormatException for malformed input by default. Use it when a network response, file, or binary payload contains UTF-8 bytes that still need to become text.
Flutter keeps text and binary data in different types. A network layer or file reader may give you bytes, while widgets expect a String. The conversion belongs at that boundary. Decoding an existing String again is not useful, and mapping each byte directly to one character is also incorrect for multibyte UTF-8.

How Flutter's UTF-8 decoder works
Dart's dart:convert library provides an utf8 codec with two opposite operations. utf8.encode(text) converts a Dart string into a sequence of UTF-8 bytes, while utf8.decode(bytes) converts those bytes back into text. Each byte has a value from 0 through 255, but one visible character may require several bytes. A supplementary character such as an emoji can require four UTF-8 bytes.
The default Flutter decoding behavior is strict. Truncated sequences, overlong encodings, surrogate encodings, isolated continuation bytes, and values beyond the Unicode range cause an error instead of producing misleading replacement text. Dart does expose an allowMalformed option, but enabling it allows malformed sequences to be represented by the Unicode replacement character U+FFFD. Treat that as a deliberate lossy fallback, not as proof that the original bytes were decoded exactly.
A byte sequence has no visible meaning without knowing its encoding. The same numbers can represent different characters under UTF-8, Windows-1252, Shift JIS, or another format. If a server or file declares a legacy encoding, use a decoder for that encoding instead of forcing its bytes through utf8.decode. The byte-level rules for UTF-8 are defined by RFC 3629.
Decode UTF-8 bytes in a Flutter app
Obtain the raw bytes. When an HTTP client exposes the response body as bytes, use its bodyBytes property. For a local file, use await file.readAsBytes(). If your client has already supplied a String, that text has already crossed a decoding boundary and should not be passed to utf8.decode again.
Import the converter. Add import 'dart:convert';. Add import 'dart:typed_data'; only when you explicitly declare a Uint8List type. No separate package is required for UTF-8 conversion.
Decode the byte list once. If bytes is a Uint8List, the core operation is:
final String text = utf8.decode(bytes);
Keep the returned String separate from the source bytes so you can compare them during troubleshooting.
Parse the result when it is JSON. JSON parsing operates on text, so decode UTF-8 first and then call jsonDecode:
final Object? payload = jsonDecode(text);
For an API response, the usual order is utf8.decode(response.bodyBytes) followed by jsonDecode. The JSON decoder does not turn raw UTF-8 bytes into characters.
Handle invalid bytes without substituting source data. Put the decode operation inside a FormatException handler:
try { final String text = utf8.decode(bytes); } on FormatException catch (error) { /* report invalid UTF-8 */ }
Preserve the original bytes for diagnosis, report the failure in the relevant UI state, and avoid continuing with partially changed or silently replaced content.
The conversion is synchronous and works on a complete byte collection. For a large response or file, avoid doing the work in a frequently rebuilt widget; move substantial decoding work away from the UI isolate and account for the memory required by both the bytes and the resulting string.
Handle malformed-byte errors without hiding the source
A decoding error does not necessarily mean the intended text was random. It can mean that a response was truncated, that reading began at the wrong byte offset, that several encodings were mixed, or that the payload was never UTF-8. Check the response headers, content length, transfer process, and original file encoding before changing the decoder settings.
For exact-content work, keep strict decoding enabled and use the original bytes to investigate the failure. If a display-only workflow genuinely tolerates data loss, utf8.decode(bytes, allowMalformed: true) is an explicit option, but the resulting U+FFFD characters must be treated as substitutions rather than recovered source text. The browser-side rationale for this distinction is covered in Decode UTF-8 Bytes Without Silent Replacement Characters.
Verify a Flutter byte sample in the browser
Open the UTF-8 Encoder / Decoder, choose UTF-8 bytes to text, and select hexadecimal, decimal, or binary notation.
Enter a short known sample using that notation's strict format. Select the conversion button and inspect the exact output rather than assuming the bytes should produce a particular character.
Compare the browser result with the Flutter result. Check the byte boundaries, representation, and starting position if they differ.
Reverse the operation by encoding the same text again, compare the resulting bytes with the original sequence, and verify a round trip before replacing original data.
For example, the hexadecimal sequence E2 82 AC decodes to the euro sign, €. Encoding € again in hexadecimal should produce that same sequence. This short round trip checks both the byte value and the direction of the conversion without involving a large payload.
The browser converter is a diagnostic aid, not a replacement for Flutter's dart:convert API. Its decoder uses fatal UTF-8 validation, so malformed input produces an explicit error. Its encoder also rejects unpaired UTF-16 surrogate code units before encoding, while valid surrogate pairs are accepted. That prevents a claimed lossless conversion from silently changing broken text.
Match hexadecimal, decimal, and binary notation correctly
| Notation | Accepted input | Produced display | Common mistake |
|---|---|---|---|
| Hexadecimal | Space- or comma-separated one- or two-digit byte tokens, optional 0x prefixes on separated tokens, or one continuous even-length hexadecimal string. | Uppercase two-digit bytes separated by spaces. | Treating the whole sequence as one hexadecimal number. |
| Decimal | Integer tokens only; each valid byte token must represent 0 through 255. | Values from 0 through 255 separated by spaces. | Combining several bytes into one oversized integer. |
| Binary | Exactly eight zero-or-one characters per token. | Exactly eight bits per byte. | Using variable-length binary instead of one eight-bit byte. |
These are three display representations of the same UTF-8 byte array. Switching from hexadecimal to binary does not change the underlying bytes. When diagnosing a format mismatch, the UTF-8 Decode Cheat Sheet: Patterns and Notation Reference provides a compact reference for byte boundaries and leading-byte patterns.
Keep UTF-8 separate from JSON and other encodings
UTF-8 maps Unicode scalar values to bytes; it is not another name for Unicode code points, UTF-16 code units, Base64, URL percent encoding, HTML entities, encryption, or compression. A Flutter JSON response normally requires two distinct operations: UTF-8 decoding turns its bytes into text, and JSON parsing turns that text into a Dart object. Base64 decoding produces bytes, while URL decoding handles percent-encoded form data.
Unicode length can also look surprising in Flutter code. A four-byte emoji is one Unicode code point but normally occupies two UTF-16 code units in a Dart string. Consequently, String.length is not the same as a count of visible Unicode characters. When you need Unicode scalar values, use the string's runes rather than treating each UTF-16 code unit as a complete character.
Know the browser tool's limits before testing a large payload
Text input is bounded at 200,000 UTF-16 code units, and decoded notation is bounded at 200,000 bytes. The converter does not stream large files or accept uploads, so use a dedicated binary tool for large data. These limits belong to the browser verification tool and are separate from the memory and performance limits of a Flutter application.
All processing stays local in the current browser tab. Text and bytes are not uploaded, logged, stored, normalized, translated, escaped for another context, or copied automatically. Start with a short known sample, choose the correct representation, inspect the byte boundaries, and verify a round trip. If legacy bytes fail, identify their original encoding rather than forcing them through UTF-8 or replacing them with an unverified character.
For a deeper look, see Base32 Decode on Windows: A Complete Local Workflow.