Last active
September 3, 2021 13:35
-
-
Save wess/327198370241fb4d30b7050a96dfa53d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
class Meta { | |
Map<String, dynamic> _backing; | |
dynamic get(String key) => _backing[key]; | |
void insert(Map<String, dynamic> data) => _backing = {..._backing, ...data}; | |
Meta set(String key, dynamic value) { | |
_backing[key] = value; | |
return this; | |
} | |
void clear() => _backing = {}; | |
String toJson() => json.encode(_backing); | |
Meta(): _backing = {}; | |
factory Meta.fromJson(String str) { | |
final meta = Meta(); | |
meta.insert( | |
json.decode(str) | |
); | |
return meta; | |
} | |
operator [](String key) => _backing[key]; | |
operator []=(String key, dynamic value) => _backing[key] = value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment