crop_your_image icon indicating copy to clipboard operation
crop_your_image copied to clipboard

[ISSUE] Unhandled Exception: This widget has been unmounted, so the State no longer has a context (and should be considered defunct).

Open ghost opened this issue 3 years ago • 5 comments

When closing page with CropEditor there is error in the console.

It happens in the method _resetCroppingArea when getting screenSize from context:

void _resetCroppingArea() {
    final screenSize = MediaQuery.of(context).size;

    final imageRatio = _targetImage!.width / _targetImage!.height;
    _isFitVertically = imageRatio < screenSize.aspectRatio;

    _imageRect = calculator.imageRect(screenSize, imageRatio);

    _resizeWith(widget.aspectRatio, widget.initialArea);
  }

image

ghost avatar Dec 14 '21 08:12 ghost

Same issue.

ShineYang avatar Feb 20 '22 13:02 ShineYang

@PTLam25 @ShineYang Hi, thank you for the issue.

I guess _CropEditor needs proper dispose() method.

Wait for update or I'll appreciate your pull requests if you have an idea to solve this.

chooyan-eng avatar Mar 08 '22 09:03 chooyan-eng

Same Problem here...

ChristophKe avatar Sep 22 '22 16:09 ChristophKe

Still a problem. EDIT: You can hide the error with: image

nyqvistatwork avatar Oct 20 '22 12:10 nyqvistatwork

I'm having the same issue in my WidgetTests, where this Widget is shown on one of my app pages:

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞══ The following assertion was thrown running a test (but after the test had completed): This widget has been unmounted, so the State no longer has a context (and should be considered defunct). Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active.

When the exception was thrown, this was the stack: #0 State.context. (package:flutter/src/widgets/framework.dart:951:9) #1 State.context (package:flutter/src/widgets/framework.dart:957:6) #2 _CropEditorState._resetCroppingArea (package:crop_your_image/src/crop.dart:369:38) #3 _CropEditorState.didChangeDependencies. (package:crop_your_image/src/crop.dart:339:9

Would appreciate an update. Thanks so much :)

NikoBoerger avatar May 16 '23 13:05 NikoBoerger