How can i add an entry to a specific index in a list?

前端 未结 4 897
天涯浪人
天涯浪人 2021-01-11 13:09

I can call list.add() which adds at the end but there is no convenient way to add an entry to a specific index which at the same time grows the list.

4条回答
  •  梦谈多话
    2021-01-11 13:57

    Dart 2

    var idx = 3;
    list.insert(idx, 'foo');
    

    Depends on whether you want to insert a single item or a bunch of items

    • https://api.dartlang.org/stable/2.1.0/dart-core/List/insert.html
    • https://api.dartlang.org/stable/2.1.0/dart-core/List/insertAll.html

    All available methods https://api.dartlang.org/stable/2.1.0/dart-core/List-class.html#instance-methods

提交回复
热议问题