Skip to content

fix(firebase_ui_database): Perform list operations in correct order #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0a78a36
Allow reversing the query for the database query builder
Rexios80 Nov 22, 2023
1cfbc35
Add the option to `FirebaseDatabaseListView` as well
Rexios80 Nov 22, 2023
edf9dca
Use the correct limit functions
Rexios80 Nov 22, 2023
e8a2f93
Merge branch 'firebase:main' into feature/database-query-builder-reverse
Rexios80 Nov 24, 2023
dee2642
Merge remote-tracking branch 'origin/main' into feature/database-quer…
Rexios80 Dec 4, 2023
3393ac7
Merge remote-tracking branch 'origin/feature/database-query-builder-r…
Rexios80 Dec 4, 2023
cd9200e
Merge remote-tracking branch 'upstream/main' into feature/database-qu…
Rexios80 Dec 11, 2023
1525a3c
Do list operations in the correct order
Rexios80 Dec 11, 2023
60b78aa
Merge branch 'firebase:main' into feature/database-query-builder-reverse
Rexios80 Jan 24, 2024
471893b
Revert "Merge branch 'firebase:main' into feature/database-query-buil…
Rexios80 Jan 24, 2024
820d16b
Revert "Revert "Merge branch 'firebase:main' into feature/database-qu…
Rexios80 Jan 24, 2024
31b4bf3
Merge branch 'firebase:main' into feature/database-query-builder-reverse
Rexios80 Jan 26, 2024
4305317
Add test
Rexios80 Jan 26, 2024
ba5e48e
Find by key instead of text
Rexios80 Jan 26, 2024
d2d5309
Cleanup
Rexios80 Jan 26, 2024
5dd84c2
Delete tests/linux/flutter/generated_plugins.cmake
russellwheatley Feb 1, 2024
4f9ecd7
Delete tests/linux/flutter/generated_plugin_registrant.cc
russellwheatley Feb 1, 2024
7211766
Delete tests/windows/flutter/generated_plugin_registrant.cc
russellwheatley Feb 1, 2024
5443120
Delete tests/windows/flutter/generated_plugins.cmake
russellwheatley Feb 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions packages/firebase_ui_database/lib/src/query_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,18 @@ class _FirestoreQueryBuilderState extends State<FirebaseDatabaseQueryBuilder> {
_snapshot = _snapshot.copyWith(isFetching: false);
}

List<DataSnapshot> docs;
if (event.snapshot.children.length < expectedDocsCount) {
docs = event.snapshot.children.toList();
} else {
docs = event.snapshot.children.take(expectedDocsCount - 1).toList();
Iterable<DataSnapshot> docs = event.snapshot.children;
if (widget.reverseQuery) {
docs = docs.toList().reversed;
}

if (widget.reverseQuery) {
docs = docs.reversed.toList();
if (event.snapshot.children.length >= expectedDocsCount) {
docs = docs.take(expectedDocsCount - 1);
}

_snapshot = _snapshot.copyWith(
hasData: true,
docs: docs,
docs: docs.toList(),
error: null,
hasMore: event.snapshot.children.length == expectedDocsCount,
stackTrace: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,56 @@ void main() {
}
},
);

testWidgets(
'Allows reversing the database query',
(tester) async {
final ref = rtdb.ref().child(_kTestPath);

await fillReference(ref, 25);
late double size;

await tester.pumpWidget(
MaterialApp(
home: Material(
child: Builder(builder: (context) {
final mq = MediaQuery.of(context);
final h = mq.size.height;
size = h / 5;

return FirebaseDatabaseListView(
physics: const ClampingScrollPhysics(),
query: ref.orderByValue(),
reverseQuery: true,
cacheExtent: 0,
pageSize: 5,
itemExtent: size,
itemBuilder: (context, snapshot) {
final v = snapshot.value as int;

return Container(
alignment: Alignment.center,
color: Colors.black.withAlpha(v % 2 == 0 ? 50 : 100),
key: ValueKey(v.toString()),
child: Text(
v.toString(),
textAlign: TextAlign.center,
),
);
},
);
}),
),
),
);

await tester.pumpAndSettle();

for (int i = 24; i >= 20; i--) {
expect(find.byKey(ValueKey(i.toString())), findsOneWidget);
}
},
);
});
}

Expand All @@ -221,4 +271,4 @@ Future<void> fillReference(DatabaseReference ref, int length) {
return Future.wait([
for (var i = 0; i < length; i++) ref.push().set(i),
]);
}
}
2 changes: 1 addition & 1 deletion tests/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
6 changes: 3 additions & 3 deletions tests/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -602,7 +602,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -651,7 +651,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
15 changes: 0 additions & 15 deletions tests/linux/flutter/generated_plugin_registrant.cc

This file was deleted.

24 changes: 0 additions & 24 deletions tests/linux/flutter/generated_plugins.cmake

This file was deleted.

23 changes: 0 additions & 23 deletions tests/windows/flutter/generated_plugin_registrant.cc

This file was deleted.

27 changes: 0 additions & 27 deletions tests/windows/flutter/generated_plugins.cmake

This file was deleted.