Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

Left and right to cancel or confirm slider flutter

I need to use a slider which slides both to the left to cancel and right to confirm

this is the desired slider

I couldn't find a way to do it, is there any way to do it ?

question from:https://stackoverflow.com/questions/65873687/left-and-right-to-cancel-or-confirm-slider-flutter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can achieve it by using a Slider and customizing it.

...

double _currentSliderValue = 5;

Slider customSlider() {
    return Slider(
      value: _currentSliderValue,
      min: 0,
      max: 10,
      divisions: 10,
      onChanged: (double value) {
        setState(() {
          _currentSliderValue = value;
        });
        if (_currentSliderValue == 0) // Decline 
        else if (_currentSliderValue == 10) // Accept
        else // Nothing
      },
    );
  }

The UI can be achieved by including the customSlider() as a child of a Row widget as follows (didn't try it but it should be the right path):


Row declineOrAcceptSlider() {
    return Row(children: [
      Text("Decline"),
      customSlider(),
      Text("Accept")
    ], mainAxisAlignment: MainAxisAlignment.spacedEvenly);
}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...