flutter - 有没有办法根据一天中的时间禁用按钮
问题描述
所以基本上我想在下午 2 点之前禁用结帐按钮,但似乎无法弄清楚如何做以及在哪里放置 if 语句逻辑。
解决方案
您可以添加您的 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)
但是,请注意:时间是当地时间!所以,可能不是你的服务器之一!
推荐阅读
- javascript - 如何将 Jquery 函数重写为 Angular 4?
- android - 如何将动态创建的 EditText 和 Spinner 放在一个 LinearLayout 中?
- php - PHP & MYSQL:为什么 mysql 不能读取 !empty?
- sql - 带有双引号字符串条件的 SQL Select 语句
- amazon-web-services - 主账户内的 Amazon S3 存储桶未在成员账户中列出
- c# - 不同控制器的不同WebAPiConfig
- php - 收到警告: implode(): 在收到 var 值后
- typescript - Ionic 3 - 在警报控制器中设置 id 值
- sorting - 在vuejs中对两个方向进行排序
- ios - 如何为 iOS 平台的 g-streamer 中的特定元素启用调试?