flutter_rounded_loading_button icon indicating copy to clipboard operation
flutter_rounded_loading_button copied to clipboard

Getting an error while trying to show the success state

Open hoponaillc opened this issue 5 years ago • 8 comments

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)

hoponaillc avatar Jul 14 '20 23:07 hoponaillc

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

chrisedg87 avatar Jul 15 '20 09:07 chrisedg87

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');
  }
 
}

alihaider78222 avatar Sep 25 '20 08:09 alihaider78222

Any solution to this?

Shruti2208 avatar Oct 09 '20 16:10 Shruti2208

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.

chrisedg87 avatar Oct 09 '20 18:10 chrisedg87

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!

robinvanyang avatar Nov 06 '20 10:11 robinvanyang

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.

dumabg avatar Jan 22 '21 21:01 dumabg

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.

Mufaddal1125 avatar Jul 17 '21 13:07 Mufaddal1125

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.

hagar-yasser avatar Aug 22 '21 12:08 hagar-yasser