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

While editing the numbers manually the incDecFactor is not considered.

Abhilash-Chandran opened this issue · comments

When editing the numbers, user are able to enter different number without getting affected by the increment decrement factor.
manual_edit

As @abulka mentioned in another discussion:

  • A relaxed interpretation of what should happen would be that the user can enter anything in range, and the inc/dec works off that.
  • The other interpretation is that whatever the user enters is corrected to be a multiple of the inc/dec factor based off the min. This is bit trickier and also relies on correct settings of the min/max/inc widget values to be fully self consistent. For example I could set up min: -1 max: 4 inc: 2 and never be able to get to 4. I could enter 4 manually and it would auto-correct to a multiple of the inc. factor starting from min, which would be 3. The user might not be so happy, since the max is 4 !

Solution approach:

  1. Based on the min, max and incDecFactor decide whether the max value is inclusive or not.
  2. Always round the manually entered value to the nearest allowed number.

Case-1:
min = 1, max=5 and incDecFactor=2.
* In this case the allowed values will be 1, 3 and 5.
* Includes the max value 5.

Case-2:
min = 1, max=6 and incDecFactor=2.
* In this case the allowed values will be 1, 3 and 5.
* Excludes the max value 6.

Case-3:
min = 1, max=3 and incDecFactor=0.5.
* In this case the allowed values will be 1, 1.5, 2, 2.5 and 3.
* Includes the max value 3.

Case-4:
min = 1, max=2.75 and incDecFactor=0.5.
* In this case the allowed values will be 1, 1.5, 2 and 2.5.
* Excludes the max value 2.75.

This can implemented with the following equation and validate the input.
Given a user enters a value say x :

  1. Calculate y = (x - min) % incDecFactor.
  2. If y==0 && x between min and max then x is valid don't change it.
  3. If y>0 then calculate a=x+y and b=x-y.
  4. If (a % incDecFactor) == 0 && a between min and max then x=a.
  5. Else apply rule 4 on b.
  6. If none step 1 through 5 is not satisfied raise a an error noting possible valid values.

Found a better approach to address this. This is based on the HTML input type=number implementation of chrome. The logic is spread across multiple files.

  1. Evaluate if a stepMismatch occurs for the given input value.
  2. If yes then buildup alternative candidates and show error message.