0

我想要一个可以按住的按钮,然后 Setstate 会重复,除非我停止按住它。

我是一名初学者,正在使用我的第一个应用程序。我想计算体积。人们必须输入高度、宽度和深度。我不想在文本(表单)字段中,因为键盘是必需的。我找到了一个带有两个按钮的解决方案,一个添加按钮和一个减号按钮。

我有它的工作,但人们必须经常按下按钮来设置他们想要的高度值。

我想而不是被压迫,我使用一些东西作为暂停,柜台正在快速增加。但我不知道解决方案。

RawMaterialButton(
child: Icon(MdiIcons.minus),
onPressed: () {
setState(() {
width--;
4

2 回答 2

3

如果您对这个话题仍然感兴趣,您可以尝试一下holding_gesture,请参阅https://pub.dev/packages/holding_gesture

于 2020-04-28T14:54:04.333 回答
0

好吧,我没修。作为初学者,这对我来说太复杂了。我找到了另一个解决方案。我做了一行,三个孩子:一个减号按钮和一个加号按钮,用于微调滑块的大步骤。

这是我使用的代码,你有更好的解决方案,让我知道。我只是为像我这样的其他初学者放置它。我要感谢特别想帮助我的@Abbas.M。

Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    AnimatedOpacity(
                      opacity: height == 1 ? 0.0 : 1.0,
                      duration: Duration(milliseconds: 500),
                      child: RawMaterialButton(
                        child: Icon(MdiIcons.minus),
                        onPressed: () {
                          setState(() {
                            height > 1 ? height-- : height = height;
                          });
                        },
                        constraints: BoxConstraints.tightFor(
                          width: 25.0,
                          height: 25.0,
                        ),
                        shape: CircleBorder(),
                        fillColor: white,
                      ),
                    ),
                    SliderTheme(
                      data: SliderTheme.of(context).copyWith(
                        inactiveTrackColor: cAppBottomBar,
                        activeTrackColor: white,
                        thumbColor: white,
                        overlayColor: cShadow,
                        thumbShape:
                            RoundSliderThumbShape(enabledThumbRadius: 10.0),
                        overlayShape:
                            RoundSliderOverlayShape(overlayRadius: 17.0),
                      ),
                      child: Slider(
                          value: height.toDouble(),
                          min: 1,
                          max: 300,
                          onChanged: (value) {
                            setState(() {
                              height = value.toInt();
                            });
                          }),
                    ),
                    AnimatedOpacity(
                      opacity: height == 300 ? 0.0 : 1.0,
                      duration: Duration(milliseconds: 500),
                      child: RawMaterialButton(
                        child: Icon(Icons.add),
                        onPressed: () {
                          setState(() {
                            height < 300 ? height++ : height = height;
                          });
                        },
                        constraints: BoxConstraints.tightFor(
                          width: 25.0,
                          height: 25.0,
                        ),
                        shape: CircleBorder(),
                        fillColor: white,
                      ),
                    ),
于 2019-07-17T18:31:56.047 回答