material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[Slider] java.lang.IllegalStateException: valueFrom(2.0) must be smaller than valueTo(2.0)

Open amitlodha opened this issue 3 years ago • 9 comments

Description: When i set value to slider having same valueTo and ValueFrom it crash

Crash Logs: java.lang.IllegalStateException: valueFrom(2.0) must be smaller than valueTo(2.0) at com.google.android.material.slider.BaseSlider.validateValueFrom(BaseSlider.java:520) at com.google.android.material.slider.BaseSlider.validateConfigurationIfDirty(BaseSlider.java:608) at com.google.android.material.slider.BaseSlider.onDraw(BaseSlider.java:1662) at android.view.View.draw(View.java:22644) at android.view.View.updateDisplayListIfDirty(View.java:21519)

Suggestion: We should not throw exception instead we should accept the same value

private void validateValueFrom() { if (valueFrom >= valueTo) { throw new IllegalStateException( String.format(EXCEPTION_ILLEGAL_VALUE_FROM, valueFrom, valueTo)); } }

private void validateValueTo() { if (valueTo <= valueFrom) { throw new IllegalStateException( String.format(EXCEPTION_ILLEGAL_VALUE_TO, valueTo, valueFrom)); } }

amitlodha avatar Jun 28 '22 06:06 amitlodha

It's WAI. It's illegal to have the same ValueTo and ValueFrom. (There's no sliding range in this case.)

drchen avatar Jun 28 '22 12:06 drchen

Hi @drchen We are using slider in our search and sometime we do get only 1 result or we doing search with result having same price as we do sliding on price, there will have same value because of same price.

amitlodha avatar Jun 28 '22 12:06 amitlodha

hmm.. That's a fair point. Let me talk to the team for their opinion.

drchen avatar Jun 28 '22 15:06 drchen

@drchen Any Update on same?

amitlodha avatar Jun 30 '22 12:06 amitlodha

Hi I'm going to reopen this as a feature request. But we need to make sure the rest of the logic works in this case, so it may take us some time to implement.

drchen avatar Jun 30 '22 12:06 drchen

@drchen any update on this feature?

akhbulatov avatar Oct 15 '23 20:10 akhbulatov