applyCurrentTool method
应用当前工具的修改
Implementation
Future<void> applyCurrentTool() async {
if (_isBusy) return;
_setBusy(true);
// 在应用操作前保存当前状态到历史快照
// 注意:对于旋转操作,应用后图片会旋转,角度会重置为0
// 所以保存快照时,应该保存应用前的图片和角度为0(因为应用后角度会重置为0)
if (isRotateTool(_activeTool)) {
// 对于旋转操作,保存旋转前的状态
// 应用旋转后,图片会旋转,角度会重置为0,所以保存角度为0
_historyManager.saveSnapshot(
image: _image,
textLayers: _textLayerManager.copyLayers(),
rotationAngle: 0.0, // 应用旋转后角度会重置为0,所以保存0
scale: 0.0, // scale 会在回退时重新计算,这里保存0作为占位符
);
} else {
// 对于其他操作(裁剪、文本),正常保存当前状态
_saveStateSnapshot();
}
try {
if (isCropTool(_activeTool)) {
await _applyCrop();
} else if (isRotateTool(_activeTool)) {
await _applyRotation();
} else if (_activeTool == EditToolsMenu.text) {
// [新增] 处理添加文本的逻辑
_applyText();
}
// 关闭工具菜单
_activeTool = EditToolsMenu.none;
notifyListeners();
} finally {
_setBusy(false);
}
}