我正在使用flutterSilder依赖项,因为它使我可以使用“FluterSliderSteps”,从而使值的非线性增加成为可能(指数)。现在我遇到的问题是我不知道如何从滑块中获取当前值,以便使用它将值显示为其他地方的文本或保存/使用它。下面我放了一些基本代码,展示了基础。有一个填充字段类,顶部有一个文本字段,上面写着“myFeedbackText”,它应该显示该值。有人有想法吗?谢谢!https://pub.dev/packages/flutter_xlider
class flutterSlider extends StatefulWidget {
@override
_flutterSliderState createState() => _flutterSliderState();
}
class _flutterSliderState extends State<flutterSlider> {
RangeValues range = RangeValues(1, 100);
double slide = 2;
@override
Widget build(BuildContext context) {
return new Scaffold(
body: Container(
color: Color(0xffE5E5E5),
child: Center(
child: Container(
child: Align(
child: Material(
color: Colors.white,
elevation: 14.0,
borderRadius: BorderRadius.circular(24.0),
shadowColor: Color(0x802196F3),
child: Container(
width: 350.0,
height: 400.0,
child: Column(
children: <Widget>[
SizedBox(height: 30,),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Text(
"myFeedbackText", // should display currentValue
style: TextStyle(
color: Colors.black, fontSize: 22.0),
)),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Builder( //Needed to find Scaffold.of(context) and display the snackbar
builder: (BuildContext context) {
return FlutterSlider(
values: [300],
max: 500,
min: 0,
onDragging: (handlerIndex, lowerValue, upperValue) {
setState(() {});
},
step: FlutterSliderStep(
step: 1, // default
isPercentRange: true, // ranges are percents, 0% to 20% and so on... . default is true
rangeList: [
FlutterSliderRangeStep(from: 0, to: 100, step: 1),
FlutterSliderRangeStep(from: 100, to: 300, step: 5),
FlutterSliderRangeStep(from: 300, to: 500, step: 10),
]
),
);
}
),
),
),
],
)),
),
),
),
),
),
);
}
}