dangerousJsonReplace method
Extremely dangerous function - replace the entire data file with freshJson.
Customize the new data using newData - this expects a Map of form:
{
'fieldName': {
// new data for that field
}
}
For the most part, this function should not be used. If you wish to update data or add new data, use writeDataToJson. About the only use case I can think of for this function (and the only one I'm using it for) is in the case of a major data migration, where you need to extract some values from the old data file, apply some operation to update them to a new format, and re-insert them into a data file with an updated structure.
Implementation
void dangerousJsonReplace(Map<String, Map> newData) {
final rawData = freshJson;
for (final entry in newData.entries) {
rawData[entry.key] = entry.value;
}
rawData['schema'] = schemaVersion;
final stringifiedData = encoder.convert(rawData);
_putJson(stringifiedData);
}