Skip to content

Commit

Permalink
Merge pull request #11 from lvsecoto/stable
Browse files Browse the repository at this point in the history
Add parameter `allowCompleteWithEmptyEditing`
  • Loading branch information
hm21 committed Mar 14, 2024
2 parents d8da81e + 5b364d6 commit 3cf0584
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,15 @@ On desktop devices, you can click and hold a layer with the mouse to move it. Ad


### Editor Widget
| Property | Description |
|---------------------------|--------------------------------------------------------------------------|
| `byteArray` | Image data as a `Uint8List` from memory. |
| `file` | File object representing the image file. |
| `assetPath` | Path to the image asset. |
| `networkUrl` | URL of the image to be loaded from the network. |
| `onImageEditingComplete` | Callback function that is invoked when editing is finished and returns the edited image as a `Uint8List`. |
| `configs` | Configuration options for the image editor. |
| Property | Description |
|---------------------------------|-----------------------------------------------------------------------------------------------------------|
| `byteArray` | Image data as a `Uint8List` from memory. |
| `file` | File object representing the image file. |
| `assetPath` | Path to the image asset. |
| `networkUrl` | URL of the image to be loaded from the network. |
| `onImageEditingComplete` | Callback function that is invoked when editing is finished and returns the edited image as a `Uint8List`. |
| `allowCompleteWithEmptyEditing` | Whether [onImageEditingComplete] call with empty editing. | |
| `configs` | Configuration options for the image editor. |


#### Constructors
Expand Down
39 changes: 38 additions & 1 deletion lib/pro_image_editor_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ class ProImageEditor extends StatefulWidget {
/// when the editing is completed.
final ImageEditingCompleteCallback onImageEditingComplete;

/// Whether [onImageEditingComplete] call with empty editing.
///
/// The default value is false.
final bool? allowCompleteWithEmptyEditing;

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

Expand All @@ -102,6 +107,10 @@ class ProImageEditor extends StatefulWidget {
/// 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.
///
/// If `allowCompleteWithEmptyEditing` parameter is true,
/// `onImageEditingComplete` will be called even if user done nothing to image.
/// The default value is false.
///
/// 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.
Expand All @@ -110,6 +119,7 @@ class ProImageEditor extends StatefulWidget {
const ProImageEditor._({
super.key,
required this.onImageEditingComplete,
this.allowCompleteWithEmptyEditing,
this.onCloseEditor,
this.onUpdateUI,
this.byteArray,
Expand All @@ -135,6 +145,10 @@ class ProImageEditor extends StatefulWidget {
/// 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.
///
/// If `allowCompleteWithEmptyEditing` parameter is true,
/// `onImageEditingComplete` will be called even if user done nothing to image.
/// The default value is false.
///
/// 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.
Expand All @@ -144,6 +158,7 @@ class ProImageEditor extends StatefulWidget {
Uint8List byteArray, {
Key? key,
required ImageEditingCompleteCallback onImageEditingComplete,
bool? allowCompleteWithEmptyEditing,
Function? onUpdateUI,
Function? onCloseEditor,
ProImageEditorConfigs configs = const ProImageEditorConfigs(),
Expand All @@ -153,6 +168,7 @@ class ProImageEditor extends StatefulWidget {
byteArray: byteArray,
configs: configs,
onImageEditingComplete: onImageEditingComplete,
allowCompleteWithEmptyEditing: allowCompleteWithEmptyEditing,
onCloseEditor: onCloseEditor,
onUpdateUI: onUpdateUI,
);
Expand All @@ -168,6 +184,10 @@ class ProImageEditor extends StatefulWidget {
/// 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.
///
/// If `allowCompleteWithEmptyEditing` parameter is true,
/// `onImageEditingComplete` will be called even if user done nothing to image.
/// The default value is false.
///
/// 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.
Expand All @@ -178,6 +198,7 @@ class ProImageEditor extends StatefulWidget {
Key? key,
ProImageEditorConfigs configs = const ProImageEditorConfigs(),
required ImageEditingCompleteCallback onImageEditingComplete,
bool? allowCompleteWithEmptyEditing,
Function? onUpdateUI,
Function? onCloseEditor,
}) {
Expand All @@ -186,6 +207,7 @@ class ProImageEditor extends StatefulWidget {
file: file,
configs: configs,
onImageEditingComplete: onImageEditingComplete,
allowCompleteWithEmptyEditing: allowCompleteWithEmptyEditing,
onCloseEditor: onCloseEditor,
onUpdateUI: onUpdateUI,
);
Expand All @@ -201,6 +223,10 @@ class ProImageEditor extends StatefulWidget {
/// 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.
///
/// If `allowCompleteWithEmptyEditing` parameter is true,
/// `onImageEditingComplete` will be called even if user done nothing to image.
/// The default value is false.
///
/// 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.
Expand All @@ -211,6 +237,7 @@ class ProImageEditor extends StatefulWidget {
Key? key,
ProImageEditorConfigs configs = const ProImageEditorConfigs(),
required ImageEditingCompleteCallback onImageEditingComplete,
bool? allowCompleteWithEmptyEditing,
Function? onUpdateUI,
Function? onCloseEditor,
}) {
Expand All @@ -219,6 +246,7 @@ class ProImageEditor extends StatefulWidget {
assetPath: assetPath,
configs: configs,
onImageEditingComplete: onImageEditingComplete,
allowCompleteWithEmptyEditing: allowCompleteWithEmptyEditing,
onCloseEditor: onCloseEditor,
onUpdateUI: onUpdateUI,
);
Expand All @@ -234,6 +262,10 @@ class ProImageEditor extends StatefulWidget {
/// 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.
///
/// If `allowCompleteWithEmptyEditing` parameter is true,
/// `onImageEditingComplete` will be called even if user done nothing to image.
/// The default value is false.
///
/// 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.
Expand All @@ -244,6 +276,7 @@ class ProImageEditor extends StatefulWidget {
Key? key,
ProImageEditorConfigs configs = const ProImageEditorConfigs(),
required ImageEditingCompleteCallback onImageEditingComplete,
bool? allowCompleteWithEmptyEditing,
Function? onUpdateUI,
Function? onCloseEditor,
}) {
Expand All @@ -252,6 +285,7 @@ class ProImageEditor extends StatefulWidget {
networkUrl: networkUrl,
configs: configs,
onImageEditingComplete: onImageEditingComplete,
allowCompleteWithEmptyEditing: allowCompleteWithEmptyEditing,
onCloseEditor: onCloseEditor,
onUpdateUI: onUpdateUI,
);
Expand Down Expand Up @@ -1538,7 +1572,10 @@ class ProImageEditorState extends State<ProImageEditor> {
/// is in progress.
void doneEditing() async {
if (_editPosition <= 0 && _layers.isEmpty) {
return closeEditor();
final allowCompleteWithEmptyEditing = widget.allowCompleteWithEmptyEditing ?? false;
if (!allowCompleteWithEmptyEditing) {
return closeEditor();
}
}
_doneEditing = true;
LoadingDialog loading = LoadingDialog()
Expand Down

0 comments on commit 3cf0584

Please sign in to comment.