getStringProperty method
Gets a stream for a string property at the specified propertyPath.
Returns a StringPropertyStream that provides:
.stream- Emits string chunks as they are parsed.future- Completes with the full string value
Use the stream for properties where you want to display content as it arrives (e.g., displaying AI-generated text as it's typed).
Example:
final titleStream = parser.getStringProperty('title');
// React to chunks
titleStream.stream.listen((chunk) {
print('Chunk: $chunk');
});
// Or wait for complete value
final fullTitle = await titleStream.future;
Throws Exception if the property at this path is not a string.
Implementation
StringPropertyStream getStringProperty(String propertyPath) {
if (_propertyControllers[propertyPath] != null &&
_propertyControllers[propertyPath] is! StringPropertyStreamController) {
throw Exception(
'Property at path $propertyPath is not a StringPropertyStream',
);
}
final controller = _propertyControllers.putIfAbsent(
propertyPath,
() => StringPropertyStreamController(
parserController: _controller,
propertyPath: propertyPath,
),
) as StringPropertyStreamController;
return controller.propertyStream;
}