I wrote a timestamp field to a record. I now want to use it in my Flutter app, but I’m getting this error:
NoSuchMethodError: Class ‘Timestamp’ has no instance method ‘getSeconds’.
Receiver: Instance of ‘Timestamp’
Tried calling: getSeconds()
final docRef = firestore.collection(usersCollection).doc(currentUID).collection(friendsCollection).doc('a6b5Ob3TqOYPHOqssype');
final returnData = await docRef.get();
final time = returnData.get('timestamp');
print('##MyApp## database test returnData: ' + time.getSeconds());
2
Answers
The
Timestamp
class has nogetSeconds
method.Instead, use the
seconds
property:or convert it to a
DateTime
I assume you are facing this by referring to very old article/code. And now in
dart
, It is not preffered to usegetters
andsetters
as it uses implicitly.To back my point.
Refer pixels elephant’s answer
To solve the error use
seconds
instead ofgetSeconds()
time.seconds
internally it is callingTry defining the type: