Skip to content

Commit

Permalink
Fix: Close editor with custom parameters
Browse files Browse the repository at this point in the history
Details can be found in [GitHub issue #6](#6).
  • Loading branch information
hm21 committed Feb 13, 2024
1 parent c69679a commit df8b815
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 22 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

### Version 2.4.0
## Version 2.4.1
- **Fixed:** Hotfix to close the editor with custom parameters, details in [GitHub issue #6](https://github.com/hm21/pro_image_editor/issues/6)

## Version 2.4.0
#### Breaking Changes
- Updated `emoji_picker_flutter` dependency to version 2.0.0. This version introduces significant enhancements, including:
- Improved configuration options for better customization.
Expand All @@ -20,10 +23,10 @@
- **Enhancement:** Improved the fly animation within the Hero widget to provide a smoother and more visually appealing experience.

## Version 2.2.2
- **Fixed:** example bug for `emojiSet`, details in [GitHub issue #2](https://github.com/hm21/pro_image_editor/issues/2#issue-2110634675)
- **Fixed:** example bug for `emojiSet`, details in [GitHub issue #2](https://github.com/hm21/pro_image_editor/issues/2)

## Version 2.2.1
- **Fixed:** close warning bug, details in [GitHub issue #1](https://github.com/hm21/pro_image_editor/issues/1#issuecomment-1905984568)
- **Fixed:** close warning bug, details in [GitHub issue #1](https://github.com/hm21/pro_image_editor/issues/1)

## Version 2.2.0
- Added functionality to extend the bottomAppBar with custom widgets, providing users with more flexibility in customizing the bottom bar.
Expand Down
78 changes: 60 additions & 18 deletions lib/pro_image_editor_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class ProImageEditor extends StatefulWidget {
/// when the editing is completed.
final ImageEditingCompleteCallback onImageEditingComplete;

/// A callback function that will be called before the image editor will close.
final Function? onCloseEditor;

/// A callback function that can be used to update the UI from custom widgets.
final Function? onUpdateUI;

Expand All @@ -93,16 +96,21 @@ class ProImageEditor extends StatefulWidget {
/// The [byteArray], [assetPath], [networkUrl], and [file] parameters represent different
/// sources of the image data. At least one of these parameters must not be null.
///
/// The [configs] parameter allows you to customize the image editing experience by providing
/// The `configs` parameter allows you to customize the image editing experience by providing
/// various configuration options. If not specified, default settings will be used.
///
/// The [onImageEditingComplete] parameter is a callback function that will be called when the editing is done,
/// The `onImageEditingComplete` parameter is a callback function that will be called when the editing is done,
/// and it returns the edited image as a Uint8List.
///
/// The [onUpdateUI] parameter is a callback function that can be used to update the UI from custom widgets.
/// The `onCloseEditor` parameter is a callback function that gets invoked when the editor is closed.
/// You can use this callback if you want to close the editor with your own parameters or if you want
/// to prevent Navigator.pop(context) from being automatically triggered.
///
/// The `onUpdateUI` parameter is a callback function that can be used to update the UI from custom widgets.
const ProImageEditor._({
super.key,
required this.onImageEditingComplete,
this.onCloseEditor,
this.onUpdateUI,
this.byteArray,
this.assetPath,
Expand All @@ -121,25 +129,31 @@ class ProImageEditor extends StatefulWidget {
///
/// The `byteArray` parameter should contain the image data as a `Uint8List`.
///
/// The [configs] parameter allows you to customize the image editing experience by providing
/// The `configs` parameter allows you to customize the image editing experience by providing
/// various configuration options. If not specified, default settings will be used.
///
/// The [onImageEditingComplete] parameter is a callback function that will be called when the editing is done,
/// The `onImageEditingComplete` parameter is a callback function that will be called when the editing is done,
/// and it returns the edited image as a Uint8List.
///
/// The [onUpdateUI] parameter is a callback function that can be used to update the UI from custom widgets.
/// The `onCloseEditor` parameter is a callback function that gets invoked when the editor is closed.
/// You can use this callback if you want to close the editor with your own parameters or if you want
/// to prevent Navigator.pop(context) from being automatically triggered.
///
/// The `onUpdateUI` parameter is a callback function that can be used to update the UI from custom widgets.
factory ProImageEditor.memory(
Uint8List byteArray, {
Key? key,
required ImageEditingCompleteCallback onImageEditingComplete,
Function? onUpdateUI,
Function? onCloseEditor,
ProImageEditorConfigs configs = const ProImageEditorConfigs(),
}) {
return ProImageEditor._(
key: key,
byteArray: byteArray,
configs: configs,
onImageEditingComplete: onImageEditingComplete,
onCloseEditor: onCloseEditor,
onUpdateUI: onUpdateUI,
);
}
Expand All @@ -148,25 +162,31 @@ class ProImageEditor extends StatefulWidget {
///
/// The `file` parameter should point to the image file.
///
/// The [configs] parameter allows you to customize the image editing experience by providing
/// The `configs` parameter allows you to customize the image editing experience by providing
/// various configuration options. If not specified, default settings will be used.
///
/// The [onImageEditingComplete] parameter is a callback function that will be called when the editing is done,
/// The `onImageEditingComplete` parameter is a callback function that will be called when the editing is done,
/// and it returns the edited image as a Uint8List.
///
/// The [onUpdateUI] parameter is a callback function that can be used to update the UI from custom widgets.
/// The `onCloseEditor` parameter is a callback function that gets invoked when the editor is closed.
/// You can use this callback if you want to close the editor with your own parameters or if you want
/// to prevent Navigator.pop(context) from being automatically triggered.
///
/// The `onUpdateUI` parameter is a callback function that can be used to update the UI from custom widgets.
factory ProImageEditor.file(
File file, {
Key? key,
ProImageEditorConfigs configs = const ProImageEditorConfigs(),
required ImageEditingCompleteCallback onImageEditingComplete,
Function? onUpdateUI,
Function? onCloseEditor,
}) {
return ProImageEditor._(
key: key,
file: file,
configs: configs,
onImageEditingComplete: onImageEditingComplete,
onCloseEditor: onCloseEditor,
onUpdateUI: onUpdateUI,
);
}
Expand All @@ -175,25 +195,31 @@ class ProImageEditor extends StatefulWidget {
///
/// The `assetPath` parameter should specify the path to the image asset.
///
/// The [configs] parameter allows you to customize the image editing experience by providing
/// The `configs` parameter allows you to customize the image editing experience by providing
/// various configuration options. If not specified, default settings will be used.
///
/// The [onImageEditingComplete] parameter is a callback function that will be called when the editing is done,
/// The `onImageEditingComplete` parameter is a callback function that will be called when the editing is done,
/// and it returns the edited image as a Uint8List.
///
/// The [onUpdateUI] parameter is a callback function that can be used to update the UI from custom widgets.
/// The `onCloseEditor` parameter is a callback function that gets invoked when the editor is closed.
/// You can use this callback if you want to close the editor with your own parameters or if you want
/// to prevent Navigator.pop(context) from being automatically triggered.
///
/// The `onUpdateUI` parameter is a callback function that can be used to update the UI from custom widgets.
factory ProImageEditor.asset(
String assetPath, {
Key? key,
ProImageEditorConfigs configs = const ProImageEditorConfigs(),
required ImageEditingCompleteCallback onImageEditingComplete,
Function? onUpdateUI,
Function? onCloseEditor,
}) {
return ProImageEditor._(
key: key,
assetPath: assetPath,
configs: configs,
onImageEditingComplete: onImageEditingComplete,
onCloseEditor: onCloseEditor,
onUpdateUI: onUpdateUI,
);
}
Expand All @@ -202,25 +228,31 @@ class ProImageEditor extends StatefulWidget {
///
/// The `networkUrl` parameter should specify the URL of the image to be loaded.
///
/// The [configs] parameter allows you to customize the image editing experience by providing
/// The `configs` parameter allows you to customize the image editing experience by providing
/// various configuration options. If not specified, default settings will be used.
///
/// The [onImageEditingComplete] parameter is a callback function that will be called when the editing is done,
/// The `onImageEditingComplete` parameter is a callback function that will be called when the editing is done,
/// and it returns the edited image as a Uint8List.
///
/// The [onUpdateUI] parameter is a callback function that can be used to update the UI from custom widgets.
/// The `onCloseEditor` parameter is a callback function that gets invoked when the editor is closed.
/// You can use this callback if you want to close the editor with your own parameters or if you want
/// to prevent Navigator.pop(context) from being automatically triggered.
///
/// The `onUpdateUI` parameter is a callback function that can be used to update the UI from custom widgets.
factory ProImageEditor.network(
String networkUrl, {
Key? key,
ProImageEditorConfigs configs = const ProImageEditorConfigs(),
required ImageEditingCompleteCallback onImageEditingComplete,
Function? onUpdateUI,
Function? onCloseEditor,
}) {
return ProImageEditor._(
key: key,
networkUrl: networkUrl,
configs: configs,
onImageEditingComplete: onImageEditingComplete,
onCloseEditor: onCloseEditor,
onUpdateUI: onUpdateUI,
);
}
Expand Down Expand Up @@ -1506,7 +1538,7 @@ class ProImageEditorState extends State<ProImageEditor> {
/// is in progress.
void doneEditing() async {
if (_editPosition <= 0 && _layers.isEmpty) {
return Navigator.pop(context);
return closeEditor();
}
_doneEditing = true;
LoadingDialog loading = LoadingDialog()
Expand All @@ -1526,6 +1558,8 @@ class ProImageEditorState extends State<ProImageEditor> {
}

if (mounted) loading.hide(context);

widget.onCloseEditor?.call();
}

/// Close the image editor.
Expand All @@ -1534,7 +1568,11 @@ class ProImageEditorState extends State<ProImageEditor> {
/// It navigates back to the previous screen or closes the modal editor.
void closeEditor() {
if (_editPosition <= 0) {
Navigator.pop(context);
if (widget.onCloseEditor == null) {
Navigator.pop(context);
} else {
widget.onCloseEditor!.call();
}
} else {
closeWarning();
}
Expand Down Expand Up @@ -1562,7 +1600,11 @@ class ProImageEditorState extends State<ProImageEditor> {
onPressed: () {
_editPosition = 0;
Navigator.pop(context, 'OK');
Navigator.pop(context);
if (widget.onCloseEditor == null) {
Navigator.pop(context);
} else {
widget.onCloseEditor!.call();
}
},
child:
Text(widget.configs.i18n.various.closeEditorWarningConfirmBtn),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pro_image_editor
description: "A Flutter image editor: Seamlessly enhance your images with user-friendly editing features."
version: 2.4.0
version: 2.4.1
homepage: https://github.com/hm21/pro_image_editor/
repository: https://github.com/hm21/pro_image_editor/
issue_tracker: https://github.com/hm21/pro_image_editor/issues/
Expand Down

0 comments on commit df8b815

Please sign in to comment.