Abhilash-Chandran / number_inc_dec

A flutter widget to accept numeric inputs with button to increment and decrement.
https://pub.dev/packages/number_inc_dec
MIT License
10 stars 7 forks source link

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

Closed cormalenv closed 4 years ago

cormalenv commented 4 years ago

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)),
)
Abhilash-Chandran commented 4 years ago

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.

cormalenv commented 4 years ago

Thanks very much @Abhilash-Chandran!

Abhilash-Chandran commented 4 years ago

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.