小编Abh*_*hGo的帖子

如何对按钮进行编程,以在点击和保持时连续增加或减少计数器?

按钮图像

截屏

我定义了一个 RoundIconButton 来增加用户点击按钮时的计数。如果用户需要将计数增加 50,则必须点击 50 次。

当用户点击并按住时,如何更改按钮以连续增加计数?

int age = 20;

RoundIconButton(
 icon: FontAwesomeIcons.plus,
 onPressed: () {
 setState(() {
 age++;
});

class RoundIconButton extends StatelessWidget {
  RoundIconButton({@required this.icon, @required this.onPressed});

  final IconData icon;
  final Function onPressed;

  @override
  Widget build(BuildContext context) {
    return RawMaterialButton(
      child: Icon(icon),
      onPressed: onPressed,
      elevation:
      6.0, // will show only when onpress is defined. it is disabled by default.
      shape: CircleBorder(),
      fillColor: Color(0xFF4C4F5E),
      constraints: BoxConstraints.tightFor(
        width: 56.0,
        height: 56.0,
      ),
    );
  }
}


Run Code Online (Sandbox Code Playgroud)

dart flutter

6
推荐指数
1
解决办法
4141
查看次数

标签 统计

dart ×1

flutter ×1