[英]Flutter Floating Action Button with Dynamic Status
Putting the finishing touches on my first Flutter mobile app.完成我的第一个 Flutter 移动应用程序。 Another important ToDo: My Floating Action Button appears in the Top App Bar for every page, but i would like its status to change (enabled / disabled) depending on the current page.另一个重要的待办事项:我的浮动操作按钮出现在每个页面的顶部应用程序栏中,但我希望根据当前页面更改其状态(启用/禁用)。 Is this possible?这可能吗? if so, any tutorials, resources, reference material and / or code examples fit for a novice, would be much appreciated.如果是这样,任何适合新手的教程、资源、参考资料和/或代码示例将不胜感激。 Thanks!谢谢!
Cool, you can use Visibility :酷,你可以使用Visibility :
floatingActionButton: Visibility(
child: FloatingActionButton(...),
visible: false, // set it to false
)
Alternatively, you could use NotificationListener (more elegante but sophisticated).或者,您可以使用 NotificationListener(更优雅但更复杂)。
Please check this example from another publication请从另一个出版物中查看此示例
Edit: maybe controlling it directly in onPressed.编辑:也许直接在 onPressed 中控制它。 According to official docs :根据官方文档:
"If the onPressed callback is null, then the button will be disabled and by default will resemble a flat button in the disabledColor." “如果 onPressed 回调是 null,则该按钮将被禁用,默认情况下将类似于 disabledColor 中的平面按钮。”
FloatingActionButton(
onPressed: shouldButtonBeDisabled() ? null : () => whatToDoOnPressed,
child: Text('blablabla')
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.