toMap method
Converts the state history to a Map.
Returns a Map representing the state history of the editor, including layers, filters, stickers, and other configurations.
Implementation
Future<Map> toMap() async {
List history = [];
List<Uint8List> stickers = [];
List<EditorStateHistory> changes = List.from(stateHistory);
if (changes.isNotEmpty) changes.removeAt(0);
/// Choose history span
switch (_configs.historySpan) {
case ExportHistorySpan.current:
if (editorPosition > 0) {
changes = [changes[editorPosition - 1]];
}
break;
case ExportHistorySpan.currentAndBackward:
changes.removeRange(editorPosition, changes.length);
break;
case ExportHistorySpan.currentAndForward:
changes.removeRange(0, editorPosition - 1);
break;
case ExportHistorySpan.all:
break;
}
/// Build Layers and filters
for (EditorStateHistory element in changes) {
List layers = [];
await _convertLayers(
element: element,
layers: layers,
stickers: stickers,
imageInfos: imageInfos,
);
Map transformConfigsMap = element.transformConfigs.toMap();
history.add({
if (layers.isNotEmpty) 'layers': layers,
if (_configs.exportFilter && element.filters.isNotEmpty)
'filters': element.filters,
'blur': element.blur,
if (transformConfigsMap.isNotEmpty) 'transform': transformConfigsMap,
});
}
return {
'version': ExportImportVersion.version_2_0_0,
'position': _configs.historySpan == ExportHistorySpan.current ||
_configs.historySpan == ExportHistorySpan.currentAndForward
? 0
: editorPosition - 1,
if (history.isNotEmpty) 'history': history,
if (stickers.isNotEmpty) 'stickers': stickers,
'imgSize': {
'width': imageInfos.rawSize.width,
'height': imageInfos.rawSize.height,
},
};
}