newList method

  1. @override
List<T> newList(
  1. int length, {
  2. bool growable = false,
  3. bool reactive = true,
})
override

Returns a new list of this kind, which is guaranteed some properties.

The method allocates the most performant list possible. For instance, Float32Kind, will give you a dart:typed_data Float32List rather than normal List<double>.

Example

import 'package:kind/kind.dart';

void main() {
  final kind = StringKind();
  final list = kind.newList(
    3,
    growable: false,
    reactive: false,
  );
}

Implementation

@override
List<T> newList(int length, {bool growable = false, bool reactive = true}) {
  // Construct a new list.
  final defaultInstance = newInstance();
  final list = List<T>.filled(
    length,
    defaultInstance,
    growable: growable,
  );

  // Wrap with ReactiveList?
  if (reactive) {
    return ReactiveList<T>.wrap(list);
  }

  return list;
}