watchRawData method

Future<Stream> watchRawData(
  1. String tag, {
  2. String dataTag = 'data',
})

Watches raw data for a specified tag.

This method provides a stream that emits updates to the raw data associated with the given tag. It fetches the initial data from SharedPreferences and listens for further changes via the stream controller. You can optionally specify a dataTag to extract a specific value from the emitted data.

Parameters:

  • tag: A String representing the key under which the data is stored.
  • dataTag: (Optional) A String representing the key within the JSON object to retrieve. Defaults to 'data'.

Returns:

  • A Future<Stream<dynamic>> that emits the raw data as it is updated.

Throws:

  • Any errors during data retrieval or stream operations are propagated.

Implementation

Future<Stream<dynamic>> watchRawData(
  final String tag, {
  final String dataTag = 'data',
}) async {
  final StreamController<Map<String, dynamic>> controller = _getController(
    'raw_$tag',
  );

  // Initial load
  await getRawData(tag).then((final dynamic data) {
    if (data != null) {
      controller.add(<String, dynamic>{dataTag: data});
    }
  });

  return controller.stream.map(
    (final Map<String, dynamic> data) => data[dataTag],
  );
}