A flutter widget that accepts numbers along with buttons to increment and decrement. This is a simple TextFormField with buttons and logic to handle factored increments/decrements and with some additional properties like minimum and maximum allowed value. The factor of incrementing/decrementing is also configurable.
Please check the example section which provides granular examples for each options.
If you like this package give it a thumbs-up 👍.
Breaking Changes from v0.7.x
Some major changes are introduced. I am bumping the version to 0.7.x because following changes may break existing users. Please do report for any issues in the repository, which I will try to address.
autovalidatehas been replaced with
autovalidateMode. More details in TextFormField docs
In your code replace
In your code replace
autovalidateModeis by default set to
always. The morale behind this is to perform validations similar to html's
<input type='number'>tag kind validation performed in chrome. Its not upto the specification but at least mimics to its best.
enableMinMaxClampingis created to and handles the behaviour of clamping the values to
maxwhen provided. For example if
minis -2 and user enter -5 this is auto-corrected to -2. By default this is attribute is set to
onChangedis introduced which when provided will be called whenever the user edits the value. Note this callback will not be called if any validation error exists.
By default the numbers will be validated for stepped increments like in browser and suggest valid nearest possible values. The intention is to mimic the behaviour of number field in Chrome.
Install the latest version of the package by adding it to
pubspec.yamlas noted in the install page.
NumberIncrementDecrementas usual like any other flutter widget.
NumberInputWithIncrementDecrement( controller: TextEditingController(), min: -3, max: 3, ),
Demo with different options
Check the examples sections for the corresponding code snippets.
NumberInputWithIncrementDecrementwidget comes with some configurable options. The same configurations are application for
|A mandatory text editing controller to be used by the TextFormField.||This is a mandatory field because its the easiest way to access the field's value, when not using a Form widget.|
|Decides the layout of the increment/decrement buttons. Following values are possible.<br/>1. leftEnd<br/>2. rightEnd<br/>3. incLeftDecRight<br/>4.incRightDecLeft<br/>|
|This is passed down to underlying TextFormField. However this is by default to set to |
|Minimum acceptable value for this numeric field. Note: No error message will be shown. To show error a |
|Maximum acceptable value for this numeric field. Note: No error message will be shown. To show error a |
|Clamp the values to either |
|Factor by which the increment or decrement should happen. e.g. setting it 0.5 increments/decrements the field value by 0.5. This also decides what are valid steps of increment or decrement starting from the |
|An initial value to be set to the field.|
|A flag to indicate if the field only accepts integer values. To use double values set this field to false.|
|This decoration will be used by the TextFormField to handle its decoration.||An |
|This is the decoration for the ||A simple |
|bool||Passed down to the |
|A validator function which accepts a string and performs some validation. This is called when this field is wrapped inside a ||A validator that parses the number into a |
|Passed down to the |
|The number of digits after the decimal point. Used only if |
|The icon to be used for the increment button.||Icons.arrow_drop_up|
|The icon to be used for the decrement button.||Icons.arrow_drop_down|
|Decoration for the Increment Icon||Defaults to a black border in the bottom and/or top depending on the |
|Decoration for the decrement Icon||Defaults to a black border in the bottom and/or top depending on the |
|Icon color to be used for Increment button.||Defaults to color defined in |
|Icon color to be used for Decrement button.||Defaults to color defined in |
|Icon size to be used for Increment button.||Defaults to size defined in IconTheme|
|Icon size to be used for Decrement button.||Defaults to size defined in IconTheme|
|A call back function to be called on successful increment. This will not be called if the internal validators fail.|
|A call back function to be called on successful decrement. This will not be called if the internal validators fail.|
|A call back function to be called on users action denoting completion of editing the value. e.g. pressing the tick mark button. This will not be called if the internal validators fail. If |
|A call back function to be called on users action editing the value. e.g. typing a new number. This will not be called if the internal validators fail. If ||null|
|A scaling factor for the width of the widget.|
|A scaling factor for the height of the widget.|
|Show a transparent separator between the increment & decrement buttons.||false|
|Background color of the increment decrement button.<br/>This is set to ||widget to|