【发布时间】:2022-01-22 04:41:06
【问题描述】:
我有一个带有 GestureDetector 的堆栈,用于将图标转换为按钮和围绕它的圆形滑块。
Stack(
alignment: Alignment.center,
children: <Widget>[
BulbSlider(),
Positioned(
top: 25,
child: GestureDetector(
onTap: () {
debugPrint('pressed');
Vibrate.feedback(FeedbackType.selection);
},
child: Icon(
Icons.play_circle_fill_rounded,
color: kOrange,
size: 250,
),
),
),
],
),
这是截图。 我的问题是,如果我尝试拖动手柄,则无法使用滑块,但如果单击滑块的轨道,它会起作用。如果我在滑块和按钮之间单击(所以在图标之外),GestureDetectoris 触发的按钮也存在问题。
我也尝试反转这两个小部件,因此我将滑块放在 GestureDetector 顶部,但在这种情况下,滑块效果很好,但 GestureDetector 未检测到任何点击。
代码如下:
Stack(
alignment: Alignment.center,
children: <Widget>[
Positioned(
top: 25,
child: GestureDetector(
onTap: () {
debugPrint('pressed');
Vibrate.feedback(FeedbackType.selection);
},
child: Icon(
Icons.play_circle_fill_rounded,
color: kOrange,
size: 250,
),
),
),
BulbSlider(),
],
),
如果它可以帮助我把滑块的代码放在这里:
import 'package:flutter/material.dart';
import 'package:sleek_circular_slider/sleek_circular_slider.dart';
import '/const/colors.dart';
class BulbSlider extends StatefulWidget {
const BulbSlider({Key? key}) : super(key: key);
@override
_State createState() => _State();
}
class _State extends State<BulbSlider> {
double? myValue;
String valore = '';
@override
void initState() {
super.initState();
myValue = 0;
valore = '1';
}
otherMethod(String rounded) {
debugPrint("rounded: " + rounded);
valore = rounded;
}
@override
Widget build(BuildContext context) {
final slider = SleekCircularSlider(
min: 1,
max: 360,
initialValue: 1,
appearance: CircularSliderAppearance(
size: 300,
startAngle: 140,
angleRange: 260,
animationEnabled: true,
customColors: CustomSliderColors(
hideShadow: true,
trackColor: kCards,
dotColor: kWhite,
progressBarColor: kOrange,
),
customWidths: CustomSliderWidths(
shadowWidth: 30,
trackWidth: 8,
progressBarWidth: 8,
handlerSize: 10,
),
infoProperties: InfoProperties(
mainLabelStyle: TextStyle(
color: kWhite, fontSize: 20, fontWeight: FontWeight.w700),
//topLabelStyle:
// TextStyle(color: kWhite, fontSize: 20, fontWeight: FontWeight.w700),
//topLabelText: 'Seconds',
modifier: (double value) {
final sec = (value.toInt()) / 100;
return ''; // '$sec s';
},
),
),
onChange: (double weight) {
setState(() {
String newValue = weight.ceil().toInt().toString();
debugPrint(newValue);
otherMethod(newValue);
});
},
);
return Container(
child: Column(
children: <Widget>[
Center(child: slider),
Text(valore),
],
),
);
}
}
你知道如何解决吗? 谢谢
【问题讨论】:
标签: flutter stack slider gesturedetector