How can I decode a hexadecimal to a byte array in Dart?
5,054
HexDecoder
isn't actually in dart:convert
. It's in a package (also) called convert
.
You need to add it to your pubspec.yaml
and then use an import like:
import 'package:convert/convert.dart';
Then use it like this:
hex.decode('abcdef');
hex
is a const singleton instance of the codec. (The constructor is private; you don't need to instantiate your own - use the existing const instance.)
Author by
mgabz
Updated on December 10, 2022Comments
-
mgabz over 1 year
So there's the
'dart:convert'
library, which contains a HexDecoder class that doesn't seem to have a constructor (according to this). But importing it and trying to construct it doesn't work; I thought maybe there was a default constructor not mentioned.I could copy the code in the source for the convert method, but I'd rather make this a learning opportunity. Any help would be appreciated.