简体   繁体   English

FloatingActionButton onPressed 不触发

[英]FloatingActionButton onPressed not triggering

hopefully a simple one here.希望这里是一个简单的。

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.它们似乎没有触发我的 onPressed 代码,尽管我确实在日志中收到了“ViewPostImeInputStage processPointer 0”和 1 类型的事件,但似乎什么也没做。

A button:一个按钮:

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'),
      ),
    ),
  );
}

The method it is supposed to trigger:它应该触发的方法:

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

The output from pressing the button three times:按三下按钮的输出:

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

The expected output:预期输出:

Dice pressed
11
Dice pressed
2
Dice pressed
18

Anything silly I am doing here?我在这里做什么傻事?

The issue here was that it was a button that had been transformed.这里的问题是它是一个经过改造的按钮。 While this should make absolutely no difference, there are a massive amount of threads about this exact issue.虽然这应该没有什么区别,但有大量关于这个确切问题的线程。 If you move a button by transforming it to a new location, the clickable region of the button remains in its ORIGINAL location.如果通过将按钮转换到新位置来移动按钮,按钮的可点击区域将保留在其原始位置。

Yes, I said that correctly.是的,我说得对。 If you have a button in the top left of the screen, and you transform it to the bottom right, you will no longer be able to click that button in it's new location because the button thinks it is still in the top left.如果您在屏幕左上角有一个按钮,并且您将其转换到右下角,您将无法再在其新位置单击该按钮,因为该按钮认为它仍在左上角。

This is absolutely retarded and unworkable.这绝对是迟钝和行不通的。

The fix for me was to overlay some opacity widgets in the target location that are invisible, and have the onclick events trigger on these widgets instead.我的解决方法是在目标位置覆盖一些不可见的不透明度小部件,并让 onclick 事件在这些小部件上触发。 I have seen a post with a developer call this massive bug "working as intended", so don't expect this to be fixed any time soon even though it seems the entire community is calling for it.我看到一个开发人员的帖子称这个巨大的错误“按预期工作”,所以不要指望这个问题会很快得到修复,即使整个社区都在呼吁它。

If you are using a Stack in AnimatedBuider then wrap it with a big Container .如果你在AnimatedBuider中使用Stack ,那么用一个大的Container包裹它。 A 200x200 container worked in my case.一个 200x200 的容器在我的情况下工作。 The size depends on your transitions.大小取决于您的过渡。 Also, You can place your button anywhere by changing the alignment property of the stack.此外,您可以通过更改堆栈的alignment属性将按钮放置在任何位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM