Home > OS >  RangeSlider API value min and max
RangeSlider API value min and max

Time:09-13

I have several methods from API in my websockets, so i need to create the range slider which put value from sliders to Map. Now it works perfectly fine only with setting the max value not the min value. What should I change in my code to make min and max values works fine?

My API request:

 Future<Map?> fetchGains(num values, num valueMax) async {
 await hubConnection.start();
    Map? gains;
    num compensation = 1;
    if (hubConnection.state == HubConnectionState.Connected) {
      await hubConnection
          .invoke('SetGainMax', args: <Object>[valueMax])
          .then((value1) => compensation = valueMax)
          .then((value2) => hubConnection
              .invoke('GetGainMax')
              .then((value3) => gains = value3 as Map))
          .then((value) => hubConnection
              .invoke('SetGain', args: [values])
              .then((value) => compensation = values)
              .then((value) => hubConnection
                  .invoke('GetGain')
                  .then((value) => gains = value as Map?)));
    }
    hubConnection.onclose(({error}) {
      throw Exception(error);
    });
    print(gains!['min']);
    print(gains);
    return gains;
  }
} 

My range sliders where I want to manipulate with min and max value:

 var _currentRangeValues = const RangeValues(1, 16);
  @override
  Widget build(BuildContext context) {
    return FutureBuilder<Map?>(
      future: GetGainsForCameras().fetchGains(
          _currentRangeValues.end.round().toInt(),
          _currentRangeValues.end.round().toInt()),
      builder: (context, snapshot) {
SizedBox(
            child: RangeSlider(
              values: _currentRangeValues,
              activeColor: Colors.green,
              min: 1,
              max: 16,
              inactiveColor: Colors.green,
              onChanged: (RangeValues value) {
                setState(() {
                  _currentRangeValues = value;
                });
              },
            ),
          )
        ]);
      },
}

Now I can set onle max value not the min value and this I get in print {min: 1, max: 16, value: 10.0, step: 1.0} It always takes only max value, not min and max

CodePudding user response:

You're not using _currentRangeValues.start which is the min value of the slider. Probably your fetchGains call should include that.

CodePudding user response:

your are calling .end for both min and max

_currentRangeValues.end.round().toInt(),
          _currentRangeValues.end.round().toInt()

range has both start and end constructors. so

_currentRangeValues.start.round().toInt(),
          _currentRangeValues.end.round().toInt()

  • Related