所以从本质上讲,我想在2pm之前禁用一个checkout按钮,但似乎无法弄清楚如何做以及在何处放置if语句逻辑。
答案 0 :(得分:0)
以下按钮将在凌晨1点至凌晨3点之间保持禁用状态。
RaisedButton(
onPressed: (DateTime.now().hour >= 1 && DateTime.now().hour <= 3) ? null : () => whatToDoOnPressed,
child: Text('Button text')
);
以下按钮将保持禁用状态,直到下午2点
RaisedButton(
onPressed: (DateTime.now().hour < 14) ? null : () => whatToDoOnPressed,
child: Text('Button text')
);
答案 1 :(得分:0)
您可以添加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)
但是,请注意: 时间是当地时间!因此,可能不是您的服务器之一!