程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了为什么我在尝试更新我的个人资料图片时遇到此错误?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决为什么我在尝试更新我的个人资料图片时遇到此错误??

开发过程中遇到为什么我在尝试更新我的个人资料图片时遇到此错误?的问题如何解决?下面主要结合日常开发的经验,给出你关于为什么我在尝试更新我的个人资料图片时遇到此错误?的解决方法建议,希望对你解决为什么我在尝试更新我的个人资料图片时遇到此错误?有所启发或帮助;

大家好,当我尝试在 Flutter 中更新我的个人资料图片时出现错误。

I/BitmapCropTask(22569): Should crop: true
E/Flutter (22569): [ERROR:Flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: setState() called after dispose(): _MeinAccountState#51c31(lifecycle state: defunct,not mounted)
E/Flutter (22569): This error happens if you call setState() on a State object for a Widget that no longer appears in the Widget tree (e.g.,whose parent Widget no longer includes the Widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
E/Flutter (22569): The preferred solution is to cancel the timer or stop Listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
E/Flutter (22569): This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoID memory leaks,consIDer breaking the reference to this object during dispose().
E/Flutter (22569): #0      State.setState.<anonymous closure> (package:Flutter/src/Widgets/framework.dart:1054:9)
E/Flutter (22569): #1      State.setState (package:Flutter/src/Widgets/framework.dart:1089:6)
E/Flutter (22569): #2      _MeinAccountState._cropImage (package:projectandroIDstudiodenya/seitenleiste/meinacount.dart:464:7)
E/Flutter (22569): <asynchronous suspension>
E/Flutter (22569): 
I/Openglrenderer(22569): Davey! duration=900ms; Flags=1,IntendedVsync=404683725160222,Vsync=404683808493552,oldestinputEvent=9223372036854775807,NewestinputEvent=0,HandleinputStart=404683823245510,AnimationStart=404683823373510,PerformTraversalsstart=404683823679510,DrawStart=404684494965510,SyncQueued=404684496166510,SyncStart=404684547432510,IssueDrawCommandsstart=404684555113510,SwapBuffers=404684565824510,FrameCompleted=404684677131510,DequeueBufferDuration=43941000,QueueBufferDuration=55381000,GpuCompleted=0,I/Openglrenderer(22569): Davey! duration=1032ms; Flags=1,DrawStart=404684699540510,SyncQueued=404684700293510,SyncStart=404684783237510,IssueDrawCommandsstart=404684795352510,SwapBuffers=404684822351510,FrameCompleted=404684840233510,DequeueBufferDuration=1873000,QueueBufferDuration=12800000,GpuCompleted=470041226614272,

但是我没有在这个类中使用计时器。 我的代码很长,所以请告诉我您是否需要大约 400 行的孔代码,或者您是否需要确切的代码 认为问题可能出在她身上,因为在我尝试让用户上传图片之前一切正常。


class MeinAccount extends StatefulWidget {
  static const route = '/MeinAccount';

  @overrIDe
  _MeinAccountState createState() => _MeinAccountState();
}

class _MeinAccountState extends State<MeinAccount> {
  file _pickedImage;
  final picker = ImagePicker();

 Future _loadPicker(ImageSource source) async {
    final picked = await picker.getimage(source: source);
    if (this.mounted) { // This checks if the Widget is still in the tree
      setState(()  {
        setState(() {
      if (picked != null) {
        _cropImage(picked);
      } else {
        print('No image selected.');
      }
    });
    Navigator.pop(context);
      });
    }
  }
  _cropImage(Pickedfile picked) async {
    file cropped = await ImageCropper.cropImage(
        sourcePath: picked.path,aspectRatioPresets: [
          CropAspectRatioPreset.original,CropAspectRatioPreset.ratio16x9,CropAspectRatioPreset.ratio5x4
        ],maxWIDth: 800,);
    if (cropped != null) {
      setState(() {
        _pickedImage = cropped;
      });
    }
  }

  voID _showPickOptionsDialog(BuildContext context) {
    showDialog(
      context: context,builder: (context) => AlertDialog(
        content: Column(
          mainAxisSize: MainAxisSize.min,children: <Widget>[
            ListTile(
              Title: Text("Pick from gallery"),onTap: () {
                _loadPicker(ImageSource.gallery);
              },),ListTile(
              Title: Text("Take a picture"),onTap: () {
                _loadPicker(ImageSource.camera);
              },)
          ],);
  }

错误如下:

if (cropped != null) {
      setState(() {
        _pickedImage = cropped;
      });
    }

错误消失了,但现在显示的是这个

D/MediaScannerConnection(26319): Scanned /storage/emulated/0/AndroID/data/DENYAGROUP2021.com/files/Pictures/7d96cd78-0a82-47f0-b27d-96246635bc682265191042833866810.jpg to null
D/EGL_emulation(26319): eglCreateContext: 0xf0caca10: maj 3 min 0 rcv 3
D/BitmapLoadUtils(26319): maxBitmapSize: 2792
D/BitmapWorkerTask(26319): Uri scheme: file
I/Openglrenderer(26319): Davey! duration=1158ms; Flags=1,IntendedVsync=412117758196194,Vsync=412118108196180,HandleinputStart=412118118324710,AnimationStart=412118118404710,PerformTraversalsstart=412118151854710,DrawStart=412118706779710,SyncQueued=412118724588710,SyncStart=412118746374710,IssueDrawCommandsstart=412118747987710,SwapBuffers=412118918505710,FrameCompleted=412118938578710,DequeueBufferDuration=696000,QueueBufferDuration=8362000,GpuCompleted=411534615855710,I/Choreographer(26319): Skipped 53 frames!  The application may be doing too much work on its main thread.
I/Openglrenderer(26319): Davey! duration=1014ms; Flags=0,IntendedVsync=412118724868043,Vsync=412119608201341,HandleinputStart=412119616194710,AnimationStart=412119616351710,PerformTraversalsstart=412119617536710,DrawStart=412119625786710,SyncQueued=412119634157710,SyncStart=412119642144710,IssueDrawCommandsstart=412119642624710,SwapBuffers=412119673457710,FrameCompleted=412119747758710,DequeueBufferDuration=3320000,QueueBufferDuration=12352000,GpuCompleted=411534824754710,D/transformImageVIEw(26319): Image size: [960:1280]
I/BitmapCropTask(26319): Should crop: false
``

解决方法

简而言之,由于 async/await 的恶作剧,您的小部件不再在树中。

一个简单的解决方法是使用以下命令检查您的小部件是否在树中:

 if (this.mounted) { // This checks if the widget is still in the tree 
      setState(() {
      // [YOUR CODE HERE]
      });
    }
,

试试这个:

if (cropped != null) {
    if (this.mounted) { // This check whether the state object is in tree
      setState(() {
        _pickedImage = cropped;
      });
    }
  }

大佬总结

以上是大佬教程为你收集整理的为什么我在尝试更新我的个人资料图片时遇到此错误?全部内容,希望文章能够帮你解决为什么我在尝试更新我的个人资料图片时遇到此错误?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: