chooyan-eng/crop_your_image

LateInitializationError: Field '_delegate@20417691' has not been initialized.

Opened this issue · 7 comments

Hello, everyone. Thank you for taking the time to discuss this issue during your busy schedule. When I first encountered this problem in the afternoon, I improved my code and put the CropController into the constructor to ensure that the initialization is completed when the object is instantiated. In fact, he worked. But when I ran it again at night, this error occurred again. I am not sure if this is a bug, and I hope to get everyone's help. Below is the error message and some codes. Thank you

`======== Exception caught by gesture ===============================================================
The following LateError was thrown while handling a gesture:
LateInitializationError: Field '_delegate@20417691' has not been initialized.

When the exception was thrown, this was the stack:
#0 CropController._delegate (package:crop_your_image/src/controller.dart)
#1 CropController.image= (package:crop_your_image/src/controller.dart:18:33)
#2 ImageFiles.changeImageFile (package:data_matrix/model/image_files.dart:16:20)
#3 _ContentState.build... (package:data_matrix/page/content.dart:129:41)
#4 _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1084:21)
#5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:275:24)
#6 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:660:11)
#7 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:311:5)
#8 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:244:7)
#9 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:630:9)
#10 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:98:12)
#11 PointerRouter._dispatchEventToRoutes. (package:flutter/src/gestures/pointer_router.dart:143:9)
#12 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13)
#13 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:141:18)
#14 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:127:7)
#15 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:465:19)
#16 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:445:22)
#17 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:330:11)
#18 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:400:7)
#19 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:363:5)
#20 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:320:7)
#21 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:293:9)
#22 _invoke1 (dart:ui/hooks.dart:158:13)
#23 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:382:7)
#24 _dispatchPointerDataPacket (dart:ui/hooks.dart:91:31)
Handler: "onTap"
Recognizer: TapGestureRecognizer#2a833
debugOwner: GestureDetector
state: possible
won arena
finalPosition: Offset(952.5, 430.5)
finalLocalPosition: Offset(52.5, 16.8)
button: 1
sent tap down
====================================================================================================`

@override Widget build(BuildContext context) { return ChangeNotifierProvider<ImageFiles>( create: (ctx) => ImageFiles(CropController()), child: MaterialApp(

`class ImageFiles extends ChangeNotifier{
ImageFiles(this.cropController);

ImageFiles.withImageFiles(this.cropController,this.deliveryImageFile);

File? deliveryImageFile;
CropController cropController;

void changeImageFile(File newImageFile){
deliveryImageFile = newImageFile;
cropController.image = newImageFile.readAsBytesSync();
notifyListeners();
}`

return Consumer( builder: (ctx, ImageFiles imageFile, child){ return ListTile( leading: Image.file(imageFileList[index]), title: Text(imageFileList[index].path.split('\\').last,overflow: TextOverflow.visible,), onTap: (){ imageFile.changeImageFile(imageFileList[index]); }, ); }, );

+1 same problem, when i try to pick an image from user lib

Same problem.
I also try to crop an image from user library.

Workaround:
it is ok after the controller has been built at least once. (I guess).

Thank you all for your feedback and suggestions.

@ZhongGuanbin
Can you provide the minimum code to reproduce the issue?
It'll be great if the code can be run when I just copy and paste it to my VSCode.

news? I have the same problem