如何使动态按钮颤抖?

时间:2020-10-24 15:26:47

标签: flutter flutter-layout

从此按钮到 enter image description here

使用ontap制作这样的动态按钮。 enter image description here

我是个举足轻重的人(〜2个月)

1 个答案:

答案 0 :(得分:1)

尝试以下代码:

class MyWidget extends StatefulWidget {
  @override
  _MyWidgetState createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  int i = 0;

  @override
  Widget build(BuildContext context) {
    return Row(children: [
      Visibility(
        visible: i > 0,
        replacement: RaisedButton(
          color: Colors.orangeAccent,
          child: new Text("Add"),
          onPressed: () => setState(() { ++i;}),
        ),
        child: Row(
          children: [
            RaisedButton(
              color: Colors.orangeAccent,
              child: new Text("-"),
              onPressed: () => setState(() { --i;}),
            ),
            Container(
              width: 100,
              child: Text(
                i.toString(),
                textAlign: TextAlign.center,
              ),
            ),
          ],
        ),
      ),
      RaisedButton(
        color: Colors.orangeAccent,
        child: new Text("+"),
        onPressed: () => setState(() { ++i;}),
      )
    ]);
  }
}