FloatingActionButton onPressed不触发 [英] FloatingActionButton onPressed not triggering

查看:211
本文介绍了FloatingActionButton onPressed不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望这里是一个简单的

我有浮动按钮,它们具有动画效果.它们似乎没有触发我的onPressed代码,尽管我确实在日志中获得了"ViewPostImeInputStage processPointer 0"和1类事件,但它们似乎什么也没做.

I have floating buttons that are animated. They do not seem to trigger my onPressed code, just seems to do nothing although I do get the "ViewPostImeInputStage processPointer 0" and 1 type events in the logs.

一个按钮:

Widget dice() {
  return Container(
    child: FloatingActionButton(
      elevation: 5.0,
      backgroundColor: Theme.of(context).accentColor,
      heroTag: null,
      onPressed: _rollDice,
      tooltip: 'Inbox',
      child: SizedBox(
        height: 32,
        width: 32,
        child: Image.asset('lib/images/dice_button.png'),
      ),
    ),
  );
}

应该触发的方法:

_rollDice() {
  print('Dice pressed');
  int rng = new Random().nextInt(20);
  print(rng.toString());
}

按3次按钮的输出:

D/ViewRootImpl@b9525ac[MainActivity](11404): ViewPostImeInputStage processPointer 0
D/ViewRootImpl@b9525ac[MainActivity](11404): ViewPostImeInputStage processPointer 1
D/ViewRootImpl@b9525ac[MainActivity](11404): ViewPostImeInputStage processPointer 0
D/ViewRootImpl@b9525ac[MainActivity](11404): ViewPostImeInputStage processPointer 1
D/ViewRootImpl@b9525ac[MainActivity](11404): ViewPostImeInputStage processPointer 0
D/ViewRootImpl@b9525ac[MainActivity](11404): ViewPostImeInputStage processPointer 1

预期输出:

Dice pressed
11
Dice pressed
2
Dice pressed
18

我在这里做任何愚蠢的事吗?

Anything silly I am doing here?

推荐答案

如果在AnimatedBuider中使用Stack,则将其包裹在大的Container中.在我的情况下,一个200x200的容器可以正常工作.大小取决于您的转场效果. 另外,您可以通过更改堆栈的alignment属性将按钮放置在任何地方.

If you are using a Stack in AnimatedBuider then wrap it with a big Container. A 200x200 container worked in my case. The size depends on your transitions. Also, You can place your button anywhere by changing the alignment property of the stack.

这篇关于FloatingActionButton onPressed不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆