safe_local_storage 2.0.0 safe_local_storage: ^2.0.0 copied to clipboard
A safe caching library to read/write values on local storage.
import 'dart:io';
import 'package:path/path.dart';
import 'package:safe_local_storage/safe_local_storage.dart';
const data = {'foo': 'bar'};
Future<void> main() async {
final storage = SafeLocalStorage(location);
await storage.write(data);
final result = await storage.read();
print(result);
}
String get location {
final script = Platform.script.toFilePath();
final parent = File(script).parent.path;
return join(parent, 'cache.json');
}