write method
Replace the whole record.
Implementations that can, write atomically — a half-written preferences file is worse than an absent one, because the absent one is recoverable by the same code path that handles a first run.
Implementation
@override
Future<void> write(String ref, String contents) async {
final file = await _fileHandle(ref, create: true);
final writable = await file!.createWritable().toDart;
// The default truncates, and the spec has the stream land on the real
// file only at close — so a torn write leaves the previous contents
// rather than half of the new ones.
await writable.write(contents.toJS).toDart;
await writable.close().toDart;
}