How to Configure Firebase Firestore settings with Flutter
The problem is resolved from cloud_firestore 0.8.2, first upgrade the dependency in pubspec.yaml
to:
dependencies:
cloud_firestore: ^0.8.2+1
Firestore::setting
return a Future, so it must be invoked in an async function.
This is sufficient to make works the example code:
void main() async {
final Firestore firestore = Firestore();
await firestore.settings(timestampsInSnapshotsEnabled: true);
runApp(new MyApp());
}
Then, at the time of actually adding your documents, you explicitly add a createdAt
(or whatever you wanna call it) field, like so:
Firestore.instance
.collection('customer')
.add({
"name": customerNameController.text,
"createdAt": FieldValue.serverTimestamp()
}).then((res) { ...