flutter-examples icon indicating copy to clipboard operation
flutter-examples copied to clipboard

Temperature meter with negative values

Open yaymalaga opened this issue 3 years ago • 2 comments

I was taking a look to the temperature meter example and I would like to create a similar one that goes from negative to positive, starting at zero. That means, the initial value should be on the middle (0) and then animate to the current value, positive or negative.

I was able to somewhat workaround this by using a range instead of a pointer (cause it starts always on the left side instead of at the center), with a LinearGaugeRange positioned at the center and with a start/end value that swaps depending on the value's sign:

LinearGaugeRange(
    position: LinearElementPosition.cross,
    startValue: (value > 0) ? 0 : value,
    endValue: (value > 0) ? value : 0,
)

However the issue that arises with this set-up is that the the range does not animate, even if I set the property animeRange to true in the SfLinearGauge widget.

yaymalaga avatar Jul 14 '22 09:07 yaymalaga

Hi @yaymalaga,

Thanks for your patience. There is no direct support to achieve your requirement, but we can update the startValue and endValue of LinearGaugeRange through an AnimationController to achieve your requirement. We have prepared a sample for your reference and attached it below.

Sample: i392200.zip

Demo:

ezgif com-gif-maker (13)

Regards, Yuvaraj.

Yuvaraj-Gajaraj avatar Jul 19 '22 16:07 Yuvaraj-Gajaraj

Thanks for your reply! The workaround is enough for my requirements, however, would it be possible to add the enableAnimation and animationDuration properties to LinearGaugeRange so users can directly consume that? It would make the widget more similar to the others provided in the library.

yaymalaga avatar Aug 11 '22 11:08 yaymalaga

Thanks for the suggestion, we will validate the possibilities at our end to add the enableAnimation and animationDuration properties to LinearGaugeRange class.

LavanyaGowtham2021 avatar Feb 14 '24 10:02 LavanyaGowtham2021