This repository has been archived by the owner on Sep 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 143
[ Dartify ] Datasnapshot.val() failing #364
Comments
I just tried to reproduce this in tests and had to problem diff --git a/firebase/test/database_test.dart b/firebase/test/database_test.dart
index b7b382d..3db4051 100644
--- a/firebase/test/database_test.dart
+++ b/firebase/test/database_test.dart
@@ -60,6 +60,43 @@ void main() {
key = null;
});
+ test('complex', () async {
+ final myRef = database.ref('/rest/scooters');
+
+ final myKey = await myRef.push({
+ 'adopted': true,
+ 'batteryAlertSentTo': '',
+ 'batteryLevel': 0,
+ 'charging': false,
+ 'checkedoutForOPS': false,
+ 'currentSpeedMode': '2',
+ 'defaultSpeedMode': 2,
+ 'gender': 'female',
+ 'ghost': false,
+ 'iotCode': 'XX',
+ 'iotType': 'XX',
+ 'lastTelemetryUpdate': '2020-07-17T12:15:33Z',
+ 'locked': true,
+ 'macAddress': 'XX',
+ 'name': 'Enable ⚡',
+ 'needsCollection': false,
+ 'online': true,
+ 'position': {'latitude': 44.83238, 'longitude': -0.53731},
+ 'reason': '0',
+ 'region': 'Bordeaux',
+ 'status': 'HIDDEN',
+ 'vehicleCode': 'XX'
+ }).future;
+
+ print(myKey.key);
+
+ final complexObjectCollection =
+ await database.ref('/rest/scooters').once('value');
+ final snapshot = complexObjectCollection.snapshot;
+ print(snapshot.val());
+ print(snapshot.toJson());
+ });
+
test('has toJson', () {
var toJsonString = ref.toJson() as String;
expect(toJsonString, startsWith(databaseUrl)); Let me know if you can come up with a failing test. I'd love to help fix this! |
If I remove the lines : if (util.hasProperty(jsObject, 'latitude') &&
util.hasProperty(jsObject, 'longitude') &&
js.objectKeys(jsObject).length == 2) {
// This is likely a GeoPoint – return it as-is
return jsObject as GeoPoint;
} In the dartify helper, everything is working fine. I will come with a working test soon. |
Ooo! Maybe #379 fixes this, too! |
@tperraut – please grab the latest here and verify things are fixed! You need help doing that, let me know! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I tried to use firebase database from firebase.dart package. Everything is working fine with primitive types but it seems the
val()
andtoJson()
functions onDataSnapshot
are failing with exception :Calling
numChildren()
or all other function not depending ondartify
helper return the expected values.The collection "/rest/scooters" have objects like the following inside :
So something is happening in the dartify helper, it seems to be related to firestore types like GeoPoint and dart being unable to cast an object with latitude and longitude fields to it as it is actually not a firestore GeoPoint object.
Thank you for your work
The text was updated successfully, but these errors were encountered: