如何编码添加按钮,例如在颤振中放大



我需要实现一个像缩放这样的按钮,当我们单击"+"时,值应该递增,当我们单击"-"时,值应该递减,计算值应该显示在按钮上的"+"和"-"中间。

RawMaterialButton(
  fillColor: Colors.green,
    splashColor: Colors.greenAccent,
    onPressed: onPressed,
    shape:const StadiumBorder(),
    child: Padding(
      padding: const EdgeInsets.all(3.0),
      child: Row(
        children: <Widget>[
          const Icon(
            Icons.add,
            color: Colors.white,
          ),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child:  Text("ADD",
                    style: TextStyle(
                      color: Colors.white,
                    ),
            ),
          ),
          const Icon(
            Icons.remove,
            color: Colors.white,
          )
        ],
      ),
    ));

**但我不知道如何创建两个不同的按钮我只需要设计部分**

在一行中,您可以使用 IconData(-(、Text(5( 和 IconData(+(,如下所示:

Row(
    mainAxisSize: MainAxisSize.min,
    children: <Widget>[
      Expanded(
          child: Material(
        child: IconButton(
            icon: Icon(Icons.remove_circle_outline,
                color: Colors.black),
            onPressed: () {
              _decrementValue(value);
            }),
      )),
      Expanded(
          child: Text(
        '${value}',
        textAlign: TextAlign.center,
      )),
      Expanded(
          child: Material(
        child: IconButton(
            icon: Icon(Icons.add_circle_outline,
                color: Colors.black),
            onPressed: () {
              _incrementValue(value);
            }),
      )),
    ],
  ),
)

在 _incrementValue(( 和 _decrementValue(( 方法中,您可以使用您的逻辑。

最新更新