我们正在实现一个用于室内测绘的轮式移动机器人,移动应用程序使用颤振,如何将我的机器人的开始或结束日期和时间实时地存储到防火墙数据库中?
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Turn On/Off The Robot"),
),
body: Center(
child: Container(
child: FlutterSwitch(
width: 125.0,
height: 55.0,
valueFontSize: 25.0,
toggleSize: 45.0,
value: status,
borderRadius: 30.0,
padding: 8.0,
showOnOff: true,
onToggle: (val) {
setState(() {
status = val;
});
},
),
),
),
);例如,这是我希望通过打开或关闭开关按钮来获取其日期的操作,然后将其存储在实时数据库中。
发布于 2022-04-16 18:36:03
如果您使用的是Firestore,那么cloud_firestore包有“时间戳”类,可以转换为/从DatiTime对象转换。如果要在数据库中创建基于服务器的时间戳,请使用:
"myDateField": FieldValue.serverTimestamp()这是一个很好而且简单的解决方案,但是如果您没有访问时间戳类的权限,或者希望您的日期可以从任何地方访问,您可以使用纪元时间戳存储它。您可以调用.millisecondsSinceEpoch获取int值。
int epochTimestamp = myDate.millisecondsSinceEpoch要创建DateTime对象,可以使用:
DateTime myDate = DateTime.fromMillisecondsSinceEpoch(epochTimestamp)在回答您的问题时,您需要在模型中包含两个字段:例如,startDate和endDate。
/// Get the initial starting time before the route
DateTime startDate = DateTime.now();
///
/// Some logic, where you wait until the end of the route
///
/// Get the ending time after all the logic/routing is complete
DateTime endDate = DateTime.now();https://stackoverflow.com/questions/71896354
复制相似问题