getNullProperty method

NullPropertyStream getNullProperty(
  1. String propertyPath
)

Gets a stream for a null property at the specified propertyPath.

Returns a NullPropertyStream that provides:

  • .stream - Emits null when the property completes
  • .future - Completes with null

Example:

await parser.getNullProperty('optionalField').future;
print('Field is null');

Throws Exception if the property at this path is not null.

Implementation

NullPropertyStream getNullProperty(String propertyPath) {
  if (_propertyControllers[propertyPath] != null &&
      _propertyControllers[propertyPath] is! NullPropertyStreamController) {
    throw Exception(
      'Property at path $propertyPath is not a NullPropertyStream',
    );
  }
  final controller = _propertyControllers.putIfAbsent(
    propertyPath,
    () => NullPropertyStreamController(
      parserController: _controller,
      propertyPath: propertyPath,
    ),
  ) as NullPropertyStreamController;
  return controller.propertyStream;
}