简体   繁体   English

如何在 Flutter 中显示 onclick 按钮动画布局?

[英]How to show onclick button animation layout in Flutter?

I want to show a transparent layout over the screen when a button is pressed.我想在按下按钮时在屏幕上显示透明布局。

I tried by using Stack and it works fine, but when I pressed the button inside of the function(eg. ExercisePage() ) the overlay doesn't show.我尝试使用 Stack 并且它工作正常,但是当我按下函数内部的按钮(例如ExercisePage() )时,叠加层没有显示。

The overlay works when the value overlayShouldBeVisible==true .当值overlayShouldBeVisible==true时,叠加层起作用。 But changing the value of overlayShouldBeVisible from inside the ExercisePage() , button pressed event, the overlay doesn't appear.但是从ExercisePage()内部更改overlayShouldBeVisible的值,按钮按下事件,叠加层不会出现。

Stack(
      fit: StackFit.passthrough,
      children: <Widget>[

        ExercisePage(),

       overlayShouldBeVisible==true?new CorrectWrongOverlay(isCorrect) : new Container() ,
      ],
    ); 

I don't know what you're doing inside ExercisePage() but I can give you some advice.我不知道你在 ExercisePage() 里面做什么,但我可以给你一些建议。 Try to use value notifierin order to change the value of a variable https://api.flutter.dev/flutter/foundation/ValueNotifier-class.html尝试使用值通知程序以更改变量的值https://api.flutter.dev/flutter/foundation/ValueNotifier-class.html

Based on the overlayShouldBeVisible value, you can use the if condition to show CorrectWrongOverlay or not without put another widget in the tree.基于overlayShouldBeVisible 值,您可以使用if 条件来显示CorrectWrongOverlay 与否,而无需在树中放置另一个小部件。

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

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