hm21 / pro_image_editor

The pro_image_editor is a Flutter widget designed for image editing within your application. It provides a flexible and convenient way to integrate image editing capabilities into your Flutter project.
https://hm21.github.io/pro_image_editor/
BSD 3-Clause "New" or "Revised" License
94 stars 59 forks source link

[Bug]: After rotating the image emoji reset their size after history is restored #151

Closed efalco777 closed 2 months ago

efalco777 commented 2 months ago

Hello again, thanks for all the fixes so far!

Package Version

4.2.3

Flutter Version

3.22.2

Platforms

Android

How to reproduce?

Reproduction steps:

  1. Choose any photo and proceed.

  2. Rotate the photo (e.g., from horizontal to vertical) and save the change.

  3. Add any overlays and emojis, then save the changes.

Expected:

Stickers should not automatically change their previously set size.

Actual:

Each time you return to edit, the stickers become progressively smaller.

Logs (optional)

No response

Example code (optional)

class _FileEditor extends StatefulWidget {
  const _FileEditor({
    required this.file,
  });

  final File file;

  @override
  State<_FileEditor> createState() => _FileEditorState();
}

class _FileEditorState extends State<_FileEditor> {
  late GlobalKey<ProImageEditorState> _key;
  String? _historyJson;

  Uint8List? _editedPhotoBytes;
  bool _showEditor = true;

  @override
  void initState() {
    super.initState();
    _key = GlobalKey<ProImageEditorState>();
  }

  @override
  Widget build(BuildContext context) {
    return switch (_showEditor) {
      true => ProImageEditor.file(
          widget.file,
          key: _key,
          callbacks: ProImageEditorCallbacks(
            onImageEditingComplete: onImageEditingComplete,
          ),
          configs: ProImageEditorConfigs(
            stickerEditorConfigs: StickerEditorConfigs(
              enabled: true,
              buildStickers: (setLayer, scrollController) {
                return SizedBox(
                  height: 200,
                  width: double.infinity,
                  child: ElevatedButton(
                    child: const Text('Create sticker'),
                    onPressed: () {
                      final sticker = Container(
                        color: Colors.red,
                        width: 50,
                        height: 50,
                      );
                      setLayer(sticker);
                    },
                  ),
                );
              },
            ),
            stateHistoryConfigs: StateHistoryConfigs(
              initStateHistory: _historyJson != null ? ImportStateHistory.fromJson(_historyJson!) : null,
            ),
          ),
        ),
      false => Scaffold(
          body: Column(
            children: [
              SizedBox(
                height: 400,
                child: Image.memory(_editedPhotoBytes!),
              ),
              const Divider(),
              ElevatedButton(
                onPressed: () => _openEditor(),
                child: const Text('Reopen editor with the history'),
              )
            ],
          ),
        ),
    };
  }

  Future<void> onImageEditingComplete(bytes) async {
    final exportState = await _key.currentState?.exportStateHistory();
    _closeEditor(await exportState?.toJson(), bytes);
  }

  void _closeEditor(String? historyJson, Uint8List? bytes) {
    setState(() {
      _showEditor = false;
      _historyJson = historyJson;
      _editedPhotoBytes = bytes;
    });
  }

  void _openEditor() {
    print('Reopening with: ' + (_historyJson?.toString() ?? 'empty'));
    setState(() {
      _key = GlobalKey<ProImageEditorState>();
      _showEditor = true;
    });
  }
}

Device Model (optional)

Samsung Galaxy S21

efalco777 commented 2 months ago

Would greatly appreciate a fix, it's pretty much last issue I've found in the package :)

hm21 commented 2 months ago

Thank you for reporting that issue with all the details. I released version 4.2.4 which should resolve this issue. Please let me know if the issue still exists by you after you updated.