在dart中写入字节数组



这是一些元素,我需要把它们放在一个字节数组16个元素

[3A, 60, 43, 2A, 5C, 01, 21, IF, 29, 1E, 0F, 4E, 0C, 13, 28, 25]

但是我使用Uint8List来创建字节数组,但是当我添加它们时,它会给出错误

List<Uint8List> key =[3A, 60, 43, 2A, 5C, 01, 21, IF, 29, 1E, 0F, 4E, 0C, 13, 28, 25];
The element type 'int' can't be assigned to the list type 'Uint8List'. (Documentation)
Expected to find ','.
Undefined name 'A'. (Documentation)  Try correcting the name to one that is defined, or defining the name. 

如何使用这些元素创建字节数组?

如果是十六进制格式,则可以以字符串形式开始

final strings = ['3A', '60', '43', '2A']; // List<String>

如果你想把这些值转换成整数形式,你可以这样做:

final integers = strings.map((s) => int.parse(s, radix: 16)).toList(); //List<Int>

最新更新