I'm using the mpin_animation plugin in flutter. I don't understand _MpinWidgetState, why it occures error. How to fix it?
error message below
Non-nullable instance field '_animationControllers' must be initialized. (Documentation) Try adding an initializer expression, or add a field initializer in this constructor, or mark it 'late'. Non-nullable instance field '_wiggleAnimation' must be initialized. (Documentation)
class _MPinWidgetState extends State<MPinWidget>
with SingleTickerProviderStateMixin {
List<MPinAnimationController> _animationControllers;
AnimationController _wrongInputAnimationController;
Animation<double> _wiggleAnimation;
String mPin = '';
_MPinWidgetState(MPinController controller) {
controller?.addInput = addInput;
controller?.delete = delete;
controller?.notifyWrongInput = notifyWrongInput;
}
CodePudding user response:
initialise your controllers in your initState
@override
void initState() {
super.initState();
_wrongInputAnimationController = AnimationController(
vsync: this,
duration: Duration(your duration here),
);
}
CodePudding user response:
You have to initialize the fields, for example:
List<MPinAnimationController> _animationControllers = [
...
];
You have to give it something like 'a default value'.
By adding 'late' you can initialze them later in your code, for example in initState:
late List<MPinAnimationController> _animationControllers;
...
@override
void initState()
{
super.initState();
_animationControllers = [...];
}