首页 > 解决方案 > 有没有办法根据一天中的时间禁用按钮

问题描述

所以基本上我想在下午 2 点之前禁用结帐按钮,但似乎无法弄清楚如何做以及在哪里放置 if 语句逻辑。

标签: fluttertimeflutter-dependencies

解决方案


您可以添加您的 onTap 或 onPressed

onTap: (){
    // in this way everytime it press it will check the time, and not only one time on build!
    if (DateTime.now().hour < 14) return; 
    else checkout();
},

你可能想对按钮的颜色做同样的事情(不重复代码;P)

但是,请注意:时间是当地时间!所以,可能不是你的服务器之一!


推荐阅读