Skip to content

Commit

Permalink
fix(firestore): fix an issue that would cause FieldValue.increment to…
Browse files Browse the repository at this point in the history
… be interpreted as double (#12444)

* fix(firestore): fix an issue that would cause FieldValue.increment to be interpreted as double

* lower
  • Loading branch information
Lyokone committed Mar 7, 2024
1 parent 2509d91 commit e9823a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Expand Up @@ -29,6 +29,8 @@ void runFieldValueTests() {
await doc.update({'foo': FieldValue.increment(1)});
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get();
expect(snapshot.data()!['foo'], equals(3));
// Expect it to be a int
expect(snapshot.data()!['foo'], isA<int>());
});

testWidgets('increments a big number if it exists', (_) async {
Expand Down
Expand Up @@ -82,8 +82,9 @@ class FirestoreMessageCodec extends StandardMessageCodec {
} else if (value is FieldValuePlatform) {
MethodChannelFieldValue delegate = FieldValuePlatform.getDelegate(value);
final int code = _kFieldValueCodes[delegate.type]!;
// We turn int into double here to avoid precision loss.
if (delegate.type == FieldValueType.incrementInteger) {
// We turn int superior to 2^32 into double here to avoid precision loss.
if (delegate.type == FieldValueType.incrementInteger &&
(delegate.value > 2147483647 || delegate.value < -2147483648)) {
buffer.putUint8(_kIncrementDouble);
writeValue(buffer, (delegate.value as int).toDouble());
} else {
Expand Down

0 comments on commit e9823a4

Please sign in to comment.