如何拖动或滑动按钮?所以我可以增加和减少计数器
我正在使用容器和堆栈。拖动时,我看到按钮的克隆而不仅仅是一个。而且看起来好像没有任何材料。
class _DraggableButtonState extends State<DraggableButton> {
Offset _position = Offset.zero; // Current position of the button
@override
void initState() {
super.initState();
_position = widget.initialPosition;
}
@override
Widget build(BuildContext context) {
return Positioned(
left: _position.dx,
child: Draggable(
axis: Axis.horizontal,
child: widget.child,
feedback: Container(
child: widget.child,
),
onDragEnd: (details) {
setState(() {
_position = details.offset;
});
},
),
);
}
}
我不想使用任何图书馆。
Slider(
value: _value,
onChanged: (newValue) {
setState(() {
_value = newValue;
});
},
min: -50.0,
max: 50.0,
divisions: 100,
onChangeEnd: (newValue) {
int roundedValue = newValue.round();
setState(() {
_value = roundedValue.toDouble();
});
},
),