Datetime 颤振日期时间,打开关闭,如果
我想显示上午9:00到晚上20:00之间的小部件,其他时间另一个小部件如此 例如,现在13:00我的店铺开门我想展示我的店铺开门 谢谢Datetime 颤振日期时间,打开关闭,如果,datetime,flutter,Datetime,Flutter,我想显示上午9:00到晚上20:00之间的小部件,其他时间另一个小部件如此 例如,现在13:00我的店铺开门我想展示我的店铺开门 谢谢 openSaat() { return Container( width: 170, height: 40, decoration: BoxDecoration(color: Colors.black), child: Row( mainAxisAlignment: MainAxisAlignment.center
openSaat() {
return Container(
width: 170,
height: 40,
decoration: BoxDecoration(color: Colors.black),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.green,
radius: 12,
),
SizedBox(width: 5,),
Text("Open Now",style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold,color: Colors.white),)
],
),
);
}
closeSaat() {
return Container(
width: 170,
height: 40,
decoration: BoxDecoration(color: Colors.black),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.red,
radius: 12,
),
SizedBox(width: 5,),
Text("Close Now",style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold,color: Colors.white),)
],
),
),
);
}
您应该小心地使用DateTime.utc而不是DateTime.now执行此操作,并适当地调整范围。否则,它使用的是当地时间,而不是反映真实世界的时间。
@override
Widget build(BuildContext context) {
return new Scaffold(
body: currentWidget()
);
}
static DateTime now = DateTime.now();
Widget currentWidget() {
var hours = now.hour;
if (hours >= 09 && hours < 21) {
return _openSaat();
} else
return _closeSaat();
}
Widget _openSaat() {
return Container(
width: 170,
height: 40,
decoration: BoxDecoration(color: Colors.black),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircleAvatar(
backgroundColor: Colors.green,
radius: 12,
),
SizedBox(
width: 5,
),
Text(
"Open Now",
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.bold, color: Colors.white),
)
],
),
);
}
Widget _closeSaat() {
return Container(
width: 170,
height: 40,
decoration: BoxDecoration(color: Colors.black),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircleAvatar(
backgroundColor: Colors.red,
radius: 12,
),
SizedBox(
width: 5,
),
Text(
"Close Now",
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.bold, color: Colors.white),
)
],
),
),
);
}