4

I want to create a buffer that can appended things.

For example

  var allInput = new Uint8List(1);
  allInput.add(list)

But it's informed me that this is can not be modify.

1
  • 1
    I'm curious why you're using Uint8List ? We might need to make it more clear that List is probably what most people want. Commented Jan 10, 2013 at 21:47

2 Answers 2

6

Per the API docs, Uint8List is a fixed list. You could use code such as:

var allInput = new Uint8List(1);
allInput[0] = 123;

If you want a growable list, you could do something like:

var allInput = new List();
allInput.addAll(list);

or

var allInput = new List<int>();
allInput.addAll(list);

Essentially, if you provide a size specifier when creating a list, that makes it fixed size. Otherwise it's extendable (ref)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for that, indeed, I used Uint8List(1) for high performance and low memroy footprint.
2

What Chris writes in his answer is correct today, but starting soon, the generic List constructor will not be fixed length when a length argument is given. The list’s size will still be changeable afterwards. There will also be a couple of additional named constructors for List:

factory List.fixedLength(int length, {E fill: null})
factory List.filled(int length, E fill)

these will help with constructing fixed length lists and creating lists with pre-filled values.

For details on bleeding edge changes to List, see:

http://api.dartlang.org/docs/bleeding_edge/dart_core/List.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.