now method
Main function to return secure DateTime
Implementation
Future<DateTime?> now() async {
try {
if (_firebaseApp == null || _firebaseFirestore == null) {
throw ("Before using Firebase time, you need to call init().");
}
DocumentReference ref = _firebaseFirestore!.collection("_time").doc();
await ref.set({"timestamp": FieldValue.serverTimestamp()});
DocumentSnapshot snap = await ref.get(GetOptions(source: Source.server));
return (snap["timestamp"] as Timestamp?)?.toDate();
} catch (e) {
debugPrint(e.toString());
return null;
}
}