【问题标题】:How can I decode a hexadecimal to a byte array in Dart?如何在 Dart 中将十六进制解码为字节数组?
【发布时间】:2019-04-17 23:24:40
【问题描述】:

所以有'dart:convert' 库,其中包含一个似乎没有构造函数的HexDecoder 类(根据this)。但是导入它并尝试构建它是行不通的;我想也许有一个没有提到的默认构造函数。

我可以在源代码中复制 convert 方法的代码,但我更愿意将此作为学习机会。任何帮助将不胜感激。

【问题讨论】:

    标签: dart flutter hex


    【解决方案1】:

    HexDecoder 实际上不在dart:convert 中。它在一个名为 convert 的包中(也)。

    您需要将其添加到您的pubspec.yaml,然后使用如下导入:

    import 'package:convert/convert.dart';
    

    然后像这样使用它:

      hex.decode('abcdef');
    

    hex 是编解码器的 const 单例实例。 (构造函数是私有的;您不需要实例化自己的 - 使用现有的 const 实例。)

    【讨论】:

      猜你喜欢
      • 2020-11-11
      • 2020-03-04
      • 1970-01-01
      • 1970-01-01
      • 2013-01-14
      • 2017-08-23
      • 1970-01-01
      • 2014-10-10
      • 1970-01-01
      相关资源
      最近更新 更多