firebase / FirebaseUI-Flutter

Apache License 2.0
90 stars 79 forks source link

feat(ui_firestore): add `includeMetadataChanges` parameter to FirestoreQueryBuilder #349

Open cpunion opened 1 month ago

cpunion commented 1 month ago

Description

Currently FirestoreListView can't get metadata changes, the FirestoreQueryBuilder component calls Query<Document>.snapshots() without includeMetadataChanges parameter.

Related Issues

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

cpunion commented 1 month ago

I am not sure if there is a way to directly specify includeMetadataChanges when constructing the query. If there is such a method, then this PR is unnecessary.

russellwheatley commented 3 weeks ago

@cpunion - This seems good to me. I think we should also update here: https://github.com/firebase/FirebaseUI-Flutter/blob/main/packages/firebase_ui_firestore/lib/src/table_builder.dart#L267

Probably should be able to pass it into FirestoreDataTable if you could update, please?

cpunion commented 3 weeks ago

@cpunion - This seems good to me. I think we should also update here: https://github.com/firebase/FirebaseUI-Flutter/blob/main/packages/firebase_ui_firestore/lib/src/table_builder.dart#L267

Probably should be able to pass it into FirestoreDataTable if you could update, please?

There isn't any listen call, so I think it need a big change if add includeMetadataChanges?

russellwheatley commented 3 weeks ago

@cpunion - We can leave that for another time. Do you mind adding a simple test that passes in includeMetadataChanges and checks that metadata is passed in with snapshot here: https://github.com/firebase/FirebaseUI-Flutter/blob/main/tests/integration_test/firebase_ui_firestore/firestore_list_view_test.dart

Thanks 😄

cpunion commented 2 weeks ago

@cpunion - We can leave that for another time. Do you mind adding a simple test that passes in includeMetadataChanges and checks that metadata is passed in with snapshot here: https://github.com/firebase/FirebaseUI-Flutter/blob/main/tests/integration_test/firebase_ui_firestore/firestore_list_view_test.dart

I will try to add a test.

cpunion commented 1 week ago

@russellwheatley It seems that metadata changes too quickly to be captured by tester.pump*. For example, when creating and updating a document, collection.snapshots().listen(includeMetadataChanges: true) will receive a series of events in a short period of time, like this:

// These are the events from collection.add({value: 1})
received event, hasPendingWrites: true, isFromCache: true, data: ({value: 1})
received event, hasPendingWrites: true, isFromCache: false, data: ()
received event, hasPendingWrites: false, isFromCache: false, data: ()

// These are the events from collection.doc('docId').update({value: 2})
received event, hasPendingWrites: true, isFromCache: false, data: ({value: 2})
received event, hasPendingWrites: false, isFromCache: false, data: ()

When the FirestoreQueryBuilder listens to the collection, multiple setState calls occur in a very short time. tester.pump* only catches the last one, and can't catches changes of hasPendingWrites and isFromCache. I'm not sure how to properly test this case. Could you please help me? Thanks.