Abhilash-Chandran / number_inc_dec

A flutter widget to accept numeric inputs with button to increment and decrement.

Home Page:https://pub.dev/packages/number_inc_dec

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

onIncrement/onDecrement: 'Null Function()' can't be assigned to 'void Function(num)'. How to use?

cormalenv opened this issue · comments

Unable to add any statement to onIncrement or onDecrement

Simple examples
onIncrement: () {var myInt = 1}
or
onIncrement: () => myMethod(),

results in

The argument type 'Null Function()' can't be assigned to the parameter type 'void Function(num)'.
and
The argument type 'dynamic Function()' can't be assigned to the parameter type 'void Function(num)'.

Can we get an example of how to use?? Is this right?

NumberInputWithIncrementDecrement(
                      controller: myTEC,
                      min: 1,
                      max: 10,
                      initialValue: 5,
                      onIncrement: myMethod(int.parse(myTEC)),
)

Thetypedef for onIncrement and onDecrement callback is DiffIncDecCallBack as in here. The call back should be a void method which wont return any value and should accept a parameter of type num which will be passed with the incremented or decremented value depending on the scenario. Following is an example.

NumberInputWithIncrementDecrement(
                      controller: myTEC,
                      min: 1,
                      max: 10,
                      initialValue: 5,
                      onIncrement: (num newValue){
                           print('Newly incremented value is $newValue')
                      },
                      onDecrement: (num newValue){
                           print('Newly decremented value is $newValue');
                      },
)

Please check if this helps in your case. I will try to add some more documentation for the relevant section in the upcoming release.

Thanks very much @Abhilash-Chandran!

Glad it helped @cormalenv. Thanks for filing and closing the issue. Let me know if you need any other information. I am working on the documentation for the same.