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]: Standalone editors are not properly rendering the image. Exceptions are thrown. #181

Closed ember11498 closed 1 month ago

ember11498 commented 1 month ago

Package Version

4.3.3

Flutter Version

3.22.3

Platforms

Android

How to reproduce?

Just create a simple standalone cropeditor and try any of the constructors (i tried memory and asset both are throwing the same exceptions).

Just as I am writting this post I have found the problem!! there is indeed a bug.

if i push the route as:

                    Navigator.of(context).push(
                      MaterialPageRoute(
                          builder: (context) => MyCropEditor()),
                    );

it works perfectly, no issues. However, if i push with go_router package then there is a ton of exceptions

                    context.pushNamed('mycropeditor');

Logs (optional)

I/flutter ( 4008): null
D/EGL_emulation( 4008): app_time_stats: avg=259.38ms min=2.97ms max=3936.92ms count=16

════════ Exception caught by rendering library ═════════════════════════════════
Unsupported operation: Infinity or NaN toInt
The relevant error-causing widget was:
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by scheduler library ═════════════════════════════════
Unsupported operation: Infinity or NaN toInt
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════
Unsupported operation: Infinity or NaN toInt
The relevant error-causing widget was:
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════
Unsupported operation: Infinity or NaN toInt
The relevant error-causing widget was:
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════
Unsupported operation: Infinity or NaN toInt
The relevant error-causing widget was:
════════════════════════════════════════════════════════════════════════════════

Example code (optional)

class MyCropEditor extends StatefulWidget {
          const MyCropEditor({super.key});

          @override
          State<MyCropEditor> createState() => _MyCropEditorState();
        }

        class _MyCropEditorState extends State<MyCropEditor>
            with ExampleHelperState<MyCropEditor> {
          @override
          Widget build(BuildContext context) {
            return CropRotateEditor.asset(
              'assets/sun.png',
              key: editorKey,
              initConfigs: CropRotateEditorInitConfigs(
                onDone: (transformations, fitToScreenFactor) {
                  print('onDone');
                  print(transformations.toMap());
                  print('done');
                },
                onImageEditingComplete: (bytes) async {
                  print('editing complete');
                },
                onCloseEditor: () {
                  print('closing');
                  context.pop();
                },
                theme: Theme.of(context).copyWith(scaffoldBackgroundColor: Colors.red),
                //convertToUint8List: true,
                configs: ProImageEditorConfigs(
                  designMode: platformDesignMode,
                  cropRotateEditorConfigs: const CropRotateEditorConfigs(
                    //roundCropper: true,
                    canChangeAspectRatio: false,
                    initAspectRatio: 1,
                  ),
                ),
              ),
            );
          }
        }

Device Model (optional)

pixel 3

hm21 commented 1 month ago

I just tested it, but everything works fine for me, even when I use the go_router package you mention. However, I think the problem is that you are trying to send data with the flutter package flutter_bloc but your provider is below the GoRoute which can't send the data there. To test it, you can replace the editor with the code below. In case it works, the problem is as I described.

CropRotateEditor.network(
          'https://picsum.photos/id/230/2000',
          /// Other code
)
ember11498 commented 1 month ago

@hm21 i just cleaned my Build folder and started again and I am not getting errors. Anyways, just to let you know but then I tested in a real device and there was an overflow issue of 1 pixel at the bottom

image

ember11498 commented 1 month ago

@hm21 a little more context on the overflow issue but that was my mothers phone and she uses a bigger sized letter maybe that's the issue

image

hm21 commented 1 month ago

If you want to support multiple font sizes in your application, you can replace the bottombar and appbar as you can see in this example. In this case you can change that there is only an icon when your users have a bigger font size or your bottombar will grow.