Home > Blockchain >  how to write both values in value from rangeslider
how to write both values in value from rangeslider

Time:09-14

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 together? how can I write the values from the range slider to the value like it is in print alternately? The logic is this: the user moves the beginning of the slider and the value is written, then the user moves the end of the slider and the value from the end of the slider is also written. So can be done?

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(
         GetGainsForCameras().fetchGains(
        _currentRangeValues.start.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}

May thanks to everyone in answer section who noticed my mistake. Is is going to work as I want or backend devs should make some changes?

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