hydrateFromJson static method
Parses a serialized JSON string and restores the cache entries into BloomData.
Pure Dart and safe for SSR, VM, and browser environments. Extracts the dehydrated state and populates the cache using hydrate.
In the browser, obtain the string content from the DOM element (e.g. via package:web)
and pass it to this method before mounting components.
// In client application bootstrap:
const jsonString = '{"queries": [...]}';
BloomData.hydrateFromJson(
jsonString,
deserialize: (json, key) => Todo.fromJson(json as Map<String, dynamic>),
);
See also:
- hydrate, to restore from an already-decoded Map.
- dehydrateToScriptTag, to generate the script tag during SSR.
Implementation
static void hydrateFromJson(
String jsonString, {
dynamic Function(dynamic json, List<dynamic> key)? deserialize,
}) {
final decoded = jsonDecode(jsonString);
if (decoded is Map<String, dynamic>) {
hydrate(decoded, deserialize: deserialize);
} else if (decoded is Map) {
hydrate(Map<String, dynamic>.from(decoded), deserialize: deserialize);
}
}