saveDrawConfig method
dynamic
saveDrawConfig(
- dynamic id,
- dynamic lineKey
存储画线属性 设置面板用的 id是初始化的图表id. 画线样式里最后一个txtStyle增加strokeWidth: 0样式,是为了这里序列化不报错,暂时没找到问题
Implementation
saveDrawConfig(id, lineKey) async {
try {
//颜色序列化
for (var entry in config[lineKey].entries) {
if(entry.value is Map){
if(entry.value['color'] is Color){
var list = Tools.colorToARGB(entry.value['color']);
entry.value['color'] = list;
}
if(entry.value['fillc'] is Color){
entry.value['fillc'] = Tools.colorToARGB(entry.value['fillc']);
}
}
}
//复制
localConfig[lineKey] = Tools.deepCopy(config[lineKey]);
//颜色反序列化
for (var entry in config[lineKey].entries) {
if(entry.value is Map){
if(entry.value['color'] is List){
entry.value['color'] = Tools.getColorFromARGB(entry.value['color']);
}
if(entry.value['fillc'] is List){
entry.value['fillc'] = Tools.getColorFromARGB(entry.value['fillc']);
}
}
}
//修改颜色序列化
final prefs = await SharedPreferences.getInstance();
await prefs.setString('${id}drawkey', json.encode(localConfig));
} catch (error) {
// print(error);
}
}