getListProperty<E extends Object?> method

ListPropertyStream<E> getListProperty<E extends Object?>(
  1. String propertyPath, {
  2. void onElement(
    1. PropertyStream propertyStream,
    2. int index
    )?,
})

Gets a stream for a list (array) property at the specified propertyPath.

Returns a ListPropertyStream that provides:

  • .future - Completes with the full parsed list
  • .onElement() - Callback that fires when each element starts parsing
  • Chainable property getters to access elements

The optional onElement callback fires immediately when a new array element is discovered, before it's fully parsed. This enables "arm the trap" behavior for building reactive UIs:

final items = parser.getListProperty('items', onElement: (element, index) {
  print('New item at index $index started');

  if (element is MapPropertyStream) {
    element.getStringProperty('name').stream.listen((name) {
      print('Item $index name: $name');
    });
  }
});

Throws Exception if the property at this path is not a list.

Implementation

ListPropertyStream<E> getListProperty<E extends Object?>(
  String propertyPath, {
  void Function(PropertyStream propertyStream, int index)? onElement,
}) {
  if (_propertyControllers[propertyPath] != null &&
      _propertyControllers[propertyPath] is! ListPropertyStreamController) {
    throw Exception(
      'Property at path $propertyPath is not a ListPropertyStream',
    );
  }
  final controller = _propertyControllers.putIfAbsent(
    propertyPath,
    () => ListPropertyStreamController<E>(
      parserController: _controller,
      propertyPath: propertyPath,
    ),
  ) as ListPropertyStreamController<E>;
  if (onElement != null) {
    controller.addOnElementCallback(onElement);
  }
  return controller.propertyStream;
}