对我的第一个 Flutter 移动应用进行最后的润色。 另一个重要的待办事项:我的 float 操作按钮出现在每个页面的顶部应用程序栏中,但我希望根据当前页面更改其状态(启用/禁用)。这可能吗?如果是这样,任何适合新手的教程、资源、引用 Material 和/或代码示例将不胜感激。 谢谢!
最佳答案
酷,你可以使用Visibility :
floatingActionButton: Visibility(
child: FloatingActionButton(...),
visible: false, // set it to false
)
或者,您可以使用NotificationListener(更优雅但更复杂)。
请查看this example from another publication
编辑:也许可以直接在 onPressed 中控制它。 根据official docs :
“如果 onPressed 回调为 null,则该按钮将被禁用,并且默认情况下将类似于disabledColor 中的平面按钮。”
FloatingActionButton(
onPressed: shouldButtonBeDisabled() ? null : () => whatToDoOnPressed,
child: Text('blablabla')
);
关于具有动态状态的 Flutter float 操作按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62562522/