我如何将机器人的起始或结束日期和时间存储到Firebase数据库中?
我们正在实施轮式移动机器人 对于用于移动应用程序的室内映射,我如何将机器人的启动或终止日期和时间存储到Firebase数据库中?
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;
});
},
),
),
),
);
例如,这是我要通过打开或关闭开关按钮,然后存储在实时数据库中来进行日期的操作
we are implementing a Wheeled mobile robot
for indoor mapping using flutter for the mobile application, How can I store the starting or ending date and time for my robot into the firebase database in real-time?
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;
});
},
),
),
),
);
for example, this is the operation that I want to take its date by turning on or turning off the switch button, and then store in a real-time database
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是firebase firestore,则cloud_firestore软件包具有“时间戳”类,可以将其转换为Datitime对象。如果您想在数据库中创建基于服务器的时间戳,请使用:
这是一个不错的解决方案,但是如果您无法访问时间戳类或希望可以从任何地方访问您的日期,则可以使用<<<强>时期时间戳。在Flutter中,您可以调用.millisecondssepoch获取INT值
并创建可以使用的DateTime对象:
回答您的问题,您需要在模型中有2个字段:
startDate 和端date 。
If you are using Firebase Firestore, then cloud_firestore package has "Timestamp" class, that can be transformed to/from DatiTime objects. If you want to create a server-based timestamp in your database, use:
This is a nice and easy solution but in case you don't have access to Timestamp class or want your date to be accessible from anywhere you can store it with epoch timestamp. In flutter you can call .millisecondsSinceEpoch to get the int value
And to create the DateTime object you can use:
Answering your question, you need to have 2 fields in your model:
startDate and endDate for example.