Getting an error while trying to show the success state
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.
Hi @hoponaillc I'm struggling to reproduce this one. Could you post the example code you're running?
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');
}
}
Any solution to this?
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.
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!
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.
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.
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.