Skip to content

Commit b1e2ed2

Browse files
committed
feat(editor): add method to update background image
Added `updateBackgroundImage` method to update the editor's background image, mark existing screenshots as "broken" for recapture, and rebuild editor state to reflect the changes.
1 parent 5cce5bd commit b1e2ed2

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 6.2.0
4+
- **FEAT**(Main-Editor): Added `updateBackgroundImage` method to update the editor's background image.
5+
36
## 6.1.6
47
- **STYLE**: format dart code
58

lib/modules/main_editor/main_editor.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,41 @@ class ProImageEditorState extends State<ProImageEditor>
791791
}
792792
}
793793

794+
/// Replace the background image with a new image and ensures all relevant
795+
/// states are rebuilt to reflect the new background. This includes marking
796+
/// all background screenshots as "broken" to trigger re-capture with the
797+
/// new image, and rebuilding the current editor state to apply the changes.
798+
///
799+
/// The method performs the following steps:
800+
/// 1. Updates the editor's background image.
801+
/// 2. Decodes the new image to prepare it for rendering.
802+
/// 3. Marks all screenshots as "broken" so they are recaptured with the
803+
/// updated background.
804+
/// 4. Rebuilds the current editor state to ensure the new background is
805+
/// applied.
806+
Future<void> updateBackgroundImage(EditorImage image) async {
807+
editorImage = image;
808+
await decodeImage();
809+
810+
/// Mark all background captured images with the old background image as
811+
/// "broken" that the editor capture them with the new image again
812+
for (var item in stateManager.screenshots) {
813+
item.broken = true;
814+
}
815+
816+
/// Force to rebuild everything
817+
int pos = stateManager.position;
818+
EditorStateHistory oldHistory = stateManager.stateHistory[pos];
819+
820+
stateManager.stateHistory[pos] = EditorStateHistory(
821+
layers: oldHistory.layers,
822+
transformConfigs: oldHistory.transformConfigs,
823+
blur: oldHistory.blur,
824+
filters: [...oldHistory.filters],
825+
tuneAdjustments: [...oldHistory.tuneAdjustments],
826+
);
827+
}
828+
794829
/// Handle the start of a scaling operation.
795830
///
796831
/// This method is called when a scaling operation begins and initializes the

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: pro_image_editor
22
description: "A Flutter image editor: Seamlessly enhance your images with user-friendly editing features."
3-
version: 6.1.6
3+
version: 6.2.0
44
homepage: https://github.com/hm21/pro_image_editor/
55
repository: https://github.com/hm21/pro_image_editor/
66
issue_tracker: https://github.com/hm21/pro_image_editor/issues/

0 commit comments

Comments
 (0)