Skip to content

Allow converting List<int> to a JSArray / JSTypedArray #91

Open
@navaronbracke

Description

@navaronbracke

Currently, there is no easy way to pass a List<int>/Uint8List to the Blob constructor.
We have to do stuff like:

    final List<int> bytes = ...;
    final Blob blob = Blob(bytes.map((int byte) => byte.toJS).toList().toJS);

Per https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#array the constructor's field for the array supports TypedArray.

There is also no extension to convert a List<int> (which Uint8List implements) to a JSArray, since we only have that for List<JSAny?>. But int is a primitive that is allowed.

I propose we do either of (or both?)
a) add an extension that converts a List<int> to a JSArray
b) update the Blob constructor to also allow a JSTypedArray

Personally I would just add option a, since it is easy and we don't need to change the Blob constructor.

Context: flutter/flutter#137374

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions