Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting an error while trying to show the success state #14

Open
hoponaillc opened this issue Jul 14, 2020 · 8 comments
Open

Getting an error while trying to show the success state #14

hoponaillc opened this issue Jul 14, 2020 · 8 comments

Comments

@hoponaillc
Copy link

hoponaillc commented Jul 14, 2020

Getting the below error in the sample code for 3 seconds timer. Button showing in the in-progress state all the time. Any idea how to fix it?

/flutter (14084): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'call' was called on null.
E/flutter (14084): Receiver: null
E/flutter (14084): Tried calling: call()
E/flutter (14084): 0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
E/flutter (14084): 1 RoundedLoadingButtonController.success
package:rounded_loading_button/rounded_loading_button.dart:261
E/flutter (14084): 2 _LoginPageState.build._sendOTP.
package:flutterloginui/main.dart:158
E/flutter (14084): 3 _rootRun (dart:async/zone.dart:1180:38)
E/flutter (14084): 4 _CustomZone.run (dart:async/zone.dart:1077:19)
E/flutter (14084): 5 _CustomZone.runGuarded (dart:async/zone.dart:979:7)
E/flutter (14084): 6 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1019:23)
E/flutter (14084): 7 _rootRun (dart:async/zone.dart:1184:13)
E/flutter (14084): 8 _CustomZone.run (dart:async/zone.dart:1077:19)
E/flutter (14084): 9 _CustomZone.bindCallback. (dart:async/zone.dart:1003:23)
E/flutter (14084): 10 Timer._createTimer. (dart:async-patch/timer_patch.dart:23:15)
E/flutter (14084): 11 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
E/flutter (14084): 12 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
E/flutter (14084): 13 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

@chrisedg87
Copy link
Owner

chrisedg87 commented Jul 15, 2020

Hi @hoponaillc I'm struggling to reproduce this one. Could you post the example code you're running?

@alihaider78222
Copy link

I'm facing the same issue, i'm using Forms to validate data, when the form is empty on validation i get the _btnController.error() succefull call and after 3 seconds i reset the controller, and after that if i add some data and validate again then there is this error "Unhandled Exception: NoSuchMethodError: The method 'call' was called on null."

minimal code is

doingSomething() {

  try {

    if (_formKey.currentState.validate()) {
        _btnController.success();
    }
    else{
      _btnController.error();
      Timer(Duration(seconds: 3), () {
        print('here timer');
        _btnController.stop();
      });
    }
    
  } catch (e) {
    print('Catch');
  }
 
}

@Shruti2208
Copy link

Any solution to this?

@chrisedg87
Copy link
Owner

Have you tried calling reset() rather than stop()? I couldn't reproduce the error but reset would be the one to use in the above example.

@robinvanyang
Copy link

I also got this error when I use Bloc, I init the controller in the State Class.
After 2000 years debug, I found that's because RoundedLoadingButtonState's initState method calls before the controller object init, so RoundedLoadingButtonController's _addListeners() method may not called!

@dumabg
Copy link

dumabg commented Jan 22, 2021

I also got this error when the widget is hidden and shown by Flutter, for example inside a Stepper.
The problem seems that Flutter recreates the widget than has the controller, so, the controller is recreated, but the RoundedLoadingButton state isn't recreated.

I've resolved the issue overriding didChangeDependencies on RoundedLoadingButtonState:


  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    widget.controller?._addListeners(_start, _stop, _success, _error, _reset);
  }

and removing widget.controller?._addListeners(_start, _stop, _success, _error, _reset); from initState.

UPDATE: After some hours, I had the same error again. The solution isn't good.

@Mufaddal1125
Copy link
Contributor

UPDATE: After some hours, I had the same error again. The solution isn't good.

@dumabg Were you able to find a solution? I'm facing the same error. The animation only works outside Stepper.

@hagar-yasser
Copy link

The problem happens every time the widget that holds the controller changes (so the controller itself changes). The problem occurs because some fields in the controller gets initialized only one time in the initState of the RoundedLoadingButton, so when the controller changes but the state doesn't change, the fields don't get initialized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants