在颤振中同时获取3个输入值时出现问题

现在我通过这种方法获取3个输入(A,B和C)

Slider(
  value: A,
  min: 0,
  max: 100,
  divisions: 100,
  label: 'A',
  onChanged: (value) {
    setState(
      () {
        A = value.toInt();
      },
    );
  },
),

I used different slider for every input but my task is to take 3 inputs in a pie-chart(In which user will be able to set 3 values by dragging marker/courser )and the combination of all 3 inputs should be 100 but i didn't found any widget like this please suggest me any solution.enter image description here

评论
Lamb
Lamb

Maybe RangeSlider can help. It's a slider but with two thumbs. It can do the job, but I don't think it can have a distinct color for the first range (0 to first thumb) and the last range (second thumb to 100).

class Sliders extends StatefulWidget {
  @override
  _SlidersState createState() => _SlidersState();
}

class _SlidersState extends State<Sliders> {
  double start = 0.0;
  double end = 0.0;
  double a = 0.0;
  double b = 0.0;
  double c = 0.0;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        RangeSlider(
          values: RangeValues(start, end),
          onChanged: _handleOnChange,
          min: 0.0,
          max: 100.0,
        ),
        Text("A: $a"),
        Text("B: $b"),
        Text("C: $c"),
      ],
    );
  }

  void _handleOnChange(RangeValues values) {
    final start = values.start;
    final end = values.end;
    final a = start;
    final b = end - start;
    final c = 100.0 - end;
    setState(() {
      this.start = start;
      this.end = end;
      this.a = a;
      this.b = b;
      this.c = c;
    });
  }
}
点赞
评论