Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
efalco777 opened this issue Jul 2, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@efalco777
Copy link

efalco777 commented Jul 2, 2024

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 efalco777 added the bug Something isn't working label Jul 2, 2024
@efalco777
Copy link
Author

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

hm21 added a commit that referenced this issue Jul 5, 2024
After rotating the image, emoji sizes were reset upon restoring history.

resolve [#151](#151).
@hm21
Copy link
Owner

hm21 commented Jul 5, 2024

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.

@hm21 hm21 closed this as completed Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants