Ad
Type 'DateTime' Is Not A Subtype Of Type 'String' In Flutter Cloud Firestore
I'm trying to get DateTime.now() and write/read it with Cloud FireStore. But got the error
This is my code
In the UI
Text(
DateFormat('dd/MM/yyyy kk:mm')
.format(DateTime
.fromMillisecondsSinceEpoch(int.parse(document[index].data['timeCreated']))),
style: timeStyle,
),
Writing data to Firestore
Firestore.instance.runTransaction((transaction) async {
await transaction.set(
docRef,
{'timeCreated': DateTime.now().millisecondsSinceEpoch.toString()},
);
});
And got this error
I/flutter ( 3378): Another exception was thrown: type 'DateTime' is not a subtype of type 'String'
Ad
Answer
Convert to string:
int time = DateTime.now().millisecondsSinceEpoch;
String t = "$time";
Ad
source: stackoverflow.com
Related Questions
- → How can I query Firebase for an equalTo boolean parameter?
- → How can I access nested data in Firebase with React?
- → Firebase simple blog (confused with security rules)
- → Removing item in Firebase with React, re-render returns item undefined
- → AngularJS Unknown Provider Error (Firebase & AngularFire)
- → How do you pass top level component state down to Routes using react-router?
- → "this" is null in firebase query function in reactjs
- → Angular Module Failed to Load
- → Multiple dex files define Lcom/google/android/gms/internal/zzrx;
- → Joining Firebase tables in React
- → How can I make add firepad to my reactjs project?
- → How to use Cloud Functions for Firebase to prerender pages for SEO?
- → React.js component has null state?
Ad