Skip to content

Commit

Permalink
fix: null check error when using withConverter and returning null f…
Browse files Browse the repository at this point in the history
…rom `fromFirestore` (#11224)

* fix: null check error when using `withConverter` and returning null from `fromFirestore`

* add e2e test

* fix: generated firebase files

* refactor(cloud_firestore): remove issue number from test

* refactor(cloud_firestore): revert GoogleService-Info.plist

---------

Co-authored-by: Russell Wheatley <russellwheatley85@gmail.com>
  • Loading branch information
exaby73 and russellwheatley committed Jul 11, 2023
1 parent 2797de1 commit 4dd0f3f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,32 @@ void runCollectionReferenceTests() {
},
timeout: const Timeout.factor(3),
);

testWidgets(
'returning null from `fromFirestore` should not throw a null check error',
(_) async {
final foo = await initializeTest('foo');
await foo.add({'value': 42});
final fooConverter = foo.withConverter(
fromFirestore: (_, __) => null,
toFirestore: (_, __) => {}, // unused
);

final fooConverterSnapshot = fooConverter.snapshots();

await expectLater(
fooConverterSnapshot,
emits(
// ignore: prefer_void_to_null
isA<QuerySnapshot<Null>>().having((e) => e.docs, 'docs', [
// ignore: prefer_void_to_null
isA<QueryDocumentSnapshot<Null>>()
.having((e) => e.data(), 'data', null)
]),
),
);
},
);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ class _WithConverterQueryDocumentSnapshot<T extends Object?>
bool get exists => true;

@override
T data() => super.data()!;
T data() => super.data() as T;
}

0 comments on commit 4dd0f3f

Please sign in to comment.