Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

update after show causes widget not mounted crash #29

Closed
zmabies opened this issue Oct 24, 2019 · 11 comments
Closed

update after show causes widget not mounted crash #29

zmabies opened this issue Oct 24, 2019 · 11 comments
Assignees

Comments

@zmabies
Copy link

zmabies commented Oct 24, 2019

Using update method after show method causes the following crash error:
Unhandled Exception: setState() called in constructor: (lifecycle state: created, no widget, not mounted) This happens when you call setState() on a State object for a widget that hasn't been inserted into the widget tree yet. It is not necessary to call setState() in the constructor, since the state is already assumed to be dirty when it is initially created.

To Reproduce
Steps to reproduce the behavior:

  1. declare ProgressDialog and initialize in build
  2. show dialog
  3. update dialog
  4. hide dialog
  5. repeat steps 2-4 until it crashes
@tiagooliveira1
Copy link

Me too.

@fayaz07
Copy link
Owner

fayaz07 commented Oct 25, 2019

Hi, can you post sample code which I can use to test.

@fayaz07 fayaz07 self-assigned this Oct 25, 2019
@zmabies
Copy link
Author

zmabies commented Oct 27, 2019

Hello @fayaz07

please see this repo for the code:
https://github.com/zmabies/ProgressDialogTest

@fayaz07
Copy link
Owner

fayaz07 commented Oct 27, 2019

if you would like to show the dialog, when the widget is initalised, use this code

void main() => runApp(MaterialApp(home: MyApp()));

  class MyApp extends StatefulWidget {
    @override
    _MyAppState createState() => _MyAppState();
  }

  class _MyAppState extends State<MyApp> {

    ProgressDialog progressDialog;

    @override
    Widget build(BuildContext context) {
      progressDialog = ProgressDialog(context);
      WidgetsBinding.instance.addPostFrameCallback((Duration d){
        progressDialog.show();
      });
      return Scaffold(

      );
    }
  }

@fayaz07
Copy link
Owner

fayaz07 commented Oct 27, 2019

Hello @fayaz07

please see this repo for the code:
https://github.com/zmabies/ProgressDialogTest

this didn't give me any issue

@zmabies
Copy link
Author

zmabies commented Oct 27, 2019

Hello @fayaz07
please see this repo for the code:
https://github.com/zmabies/ProgressDialogTest

this didn't give me any issue

Did you test it with the navigation from home class in main?

@zmabies
Copy link
Author

zmabies commented Oct 27, 2019

if you would like to show the dialog, when the widget is initalised, use this code

void main() => runApp(MaterialApp(home: MyApp()));

  class MyApp extends StatefulWidget {
    @override
    _MyAppState createState() => _MyAppState();
  }

  class _MyAppState extends State<MyApp> {

    ProgressDialog progressDialog;

    @override
    Widget build(BuildContext context) {
      progressDialog = ProgressDialog(context);
      WidgetsBinding.instance.addPostFrameCallback((Duration d){
        progressDialog.show();
      });
      return Scaffold(

      );
    }
  }

this isn't the issue

@zmabies
Copy link
Author

zmabies commented Nov 4, 2019

Hello @fayaz07, any updates?

@furkankurt
Copy link

Still same?

@furkankurt
Copy link

@fayaz07 unfortunately issue isn't resolved. Not always but sometimes I get the error and crash.
I/flutter (18088): ProgressDialog shown E/flutter (18088): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'update' was called on null. E/flutter (18088): Receiver: null E/flutter (18088): Tried calling: update() E/flutter (18088): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5) E/flutter (18088): #1 ProgressDialog.update (package:progress_dialog/progress_dialog.dart:83:29) E/flutter (18088): #2 _EsyaIlaniEkleState.resimYukle.<anonymous closure> (package:ogrencievi/lists/post/post_esya_ilani.dart:465:18) E/flutter (18088): #3 _rootRun (dart:async/zone.dart:1122:38) E/flutter (18088): #4 _CustomZone.run (dart:async/zone.dart:1023:19) E/flutter (18088): #5 _CustomZone.runGuarded (dart:async/zone.dart:925:7) E/flutter (18088): #6 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23) E/flutter (18088): #7 _rootRun (dart:async/zone.dart:1126:13) E/flutter (18088): #8 _CustomZone.run (dart:async/zone.dart:1023:19) E/flutter (18088): #9 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:949:23) E/flutter (18088): #10 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:23:15) E/flutter (18088): #11 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19) E/flutter (18088): #12 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5) E/flutter (18088): #13 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12) E/flutter (18088):

@fayaz07
Copy link
Owner

fayaz07 commented Apr 11, 2020

Hi everyone, please use await for showing and hiding the dialog just as

await pr.show();
... your code
await pr.hide();

@fayaz07 fayaz07 closed this as completed Apr 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants