onProperty method
Registers a callback that fires when each object property starts parsing.
The callback receives:
propertyStream: A property stream for the new property (type depends on value)key: The string key of the property in the object
This fires immediately when the parser encounters the start of a new property value, before the value is fully parsed. This enables building reactive UIs that can add placeholder elements and fill them in as data arrives.
Example:
user.onProperty((property, key) {
if (property is StringPropertyStream) {
property.stream.listen((chunk) {
print('Property "$key" chunk: $chunk');
});
}
});
Implementation
void onProperty(
void Function(PropertyStream propertyStream, String key) callback,
) {
// Add callback to the controller's list
final controller =
parserController.getPropertyStreamController(_propertyPath)
as MapPropertyStreamController;
controller.addOnPropertyCallback(callback);
}