convertUint8ListToJSArrayBuffer static method

Object convertUint8ListToJSArrayBuffer(
  1. Uint8List data
)

Convert a Dart Uint8List to a js Uint8Array. Both are almost the same data type, but the web api doesn't like the Uint8List.

Implementation

static Object convertUint8ListToJSArrayBuffer(final Uint8List data) {
  final constructor = _JSUtil.getProperty(_window, "Uint8Array");
  final newArray = _JSUtil.callConstructor(constructor, [data.length]);
  for (var i = 0; i < data.length; i++) {
    _JSUtil.setProperty(newArray, i, data[i]);
  }
  return newArray;
}