Skip to content

Commit

Permalink
Merge pull request #17 from lvsecoto:stable
Browse files Browse the repository at this point in the history
Add test `allowCompleteWithEmptyEditing`
  • Loading branch information
hm21 authored Mar 15, 2024
2 parents bb8f480 + 1276e58 commit d1579b4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Version 2.5.2
- **Fix:** fix: The `allowCompleteWithEmptyEditing` logic was dropped by the committing.

## Version 2.5.1
- **Feat:** Set theme for alert dialog. Details in [GitHub pull #16](https://github.com/hm21/pro_image_editor/pull/16)

Expand Down
16 changes: 11 additions & 5 deletions lib/pro_image_editor_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,11 @@ 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 All @@ -1648,11 +1652,12 @@ class ProImageEditorState extends State<ProImageEditor> {
imageEditorTheme: widget.configs.imageEditorTheme,
);

var bytes = await _screenshotCtrl.capture(pixelRatio: _pixelRatio);
Uint8List bytes = Uint8List.fromList([]);
try {
bytes = await _screenshotCtrl.capture(pixelRatio: _pixelRatio) ?? bytes;
} catch (_) {}

if (bytes != null) {
await widget.onImageEditingComplete(bytes);
}
await widget.onImageEditingComplete(bytes);

if (mounted) loading.hide(context);

Expand Down Expand Up @@ -1960,6 +1965,7 @@ class ProImageEditorState extends State<ProImageEditor> {
onPressed: redoAction,
),
IconButton(
key: const ValueKey('TextEditorMainDoneButton'),
tooltip: widget.configs.i18n.done,
padding: const EdgeInsets.symmetric(horizontal: 8),
icon: Icon(widget.configs.icons.doneIcon),
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.5.1
version: 2.5.2
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
36 changes: 36 additions & 0 deletions test/pro_image_editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,40 @@ void main() {
final layers3 = find.byType(LayerWidget);
expect(layers3, findsOneWidget);
});

testWidgets(
'ProImageEditor performs done action with allowCompleteWithEmptyEditing',
(WidgetTester tester) async {
Future test({
required bool givingAllowCompleteWithEmptyEditing,
required bool expectedHasCompleteEdit,
}) async {
var hasCompleteEdit = false;
await tester.pumpWidget(MaterialApp(
home: ProImageEditor.memory(
fakeMemoryImage,
allowCompleteWithEmptyEditing: givingAllowCompleteWithEmptyEditing,
onImageEditingComplete: (Uint8List bytes) async {
hasCompleteEdit = true;
},
)));

// Press done button without any editing;
final doneBtn = find.byKey(const ValueKey('TextEditorMainDoneButton'));
expect(doneBtn, findsOneWidget);
await tester.tap(doneBtn);
try {
await tester.pumpAndSettle();
} catch (_) {}

expect(hasCompleteEdit, expectedHasCompleteEdit);
}

await test(
givingAllowCompleteWithEmptyEditing: true,
expectedHasCompleteEdit: true);
await test(
givingAllowCompleteWithEmptyEditing: false,
expectedHasCompleteEdit: false);
});
}

0 comments on commit d1579b4

Please sign in to comment.