我正在使用RangeSlider。我需要根据(左右拇指是幻灯片)更改文本的值。我可以根据拇指滑梯得到rangevalue的值,但我想明确知道哪个拇指滑梯了。

               RangeSlider(
                      values: rangeValues,
                      min: 0.0,
                      max: 11,
                      divisions: 11,
                      onChanged: (value) {
                        setState(() {
                          rangeValues = value;
                          if(rangeValues.start>=0){
                            range="start";
                          }
                          else if (rangeValues.end>=0){
                            range = "end";
                          }
                        });
                      })

最佳答案

这对您很有用:
flutter - 检查RangeSlider中哪个Thumb(左或右)是幻灯片-LMLPHP

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  final appTitle = 'RangeSlider Thumb Detection ';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: appTitle,
      home: MyHomePage(title: appTitle),
    );
  }
}

class MyHomePage extends StatefulWidget {
  final String title;

  MyHomePage({Key key, this.title}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>{

  RangeValues rangeValues = RangeValues(0.3, 0.7);

  String range = 'No meovement yet !';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
          Text(range, style: TextStyle(fontSize: 22.0,),),
          RangeSlider(
              values: rangeValues,
              min: 0.0,
              max: 11,
              divisions: 11,
              onChanged: (value) {
                setState(() {
                  if(value.start != rangeValues.start){
                    range = 'Left thumb';
                  }
                  if(value.end != rangeValues.end){
                    range = 'Right thumb';
                  }
                  rangeValues = value;
                });
              }),
        ],
      ),
    );
  }
}

关于flutter - 检查RangeSlider中哪个Thumb(左或右)是幻灯片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57622186/

10-12 01:57