I have 4 items in the ENTRIES table. I am trying to download them pageSize at a time (ie, before the user scrolls).
As I set pageSize=2, only 2 should be loaded.
Instead, all 4 are loaded, as verified by printing the value of index when the widget in itemBuilder finishes loading.
My theory is that this undesired behavior happens because I am calling a secondary StreamBuilder inside the itemBuilder. I need to call it in order to look up the item-associated data at another database location.
In general, the query parameter doesn't seem to be doing a listen(), only a once() or get(). How to accommodate the case when a listen() is needed?
Here's the code:
@override
Widget build(BuildContext context) {
List<String> listTest = [];
return FirebaseDatabaseListView(
pageSize: 2,
reverse: true, // also broken if set to false or omitted
shrinkWrap: true,
query: FirebaseDatabase.instance.ref('ENTRIES').orderByKey(),
itemBuilder: (context, snapshot) {
final item = snapshot.value as Map<dynamic, dynamic>;
final testShow = item[KEY_ID];
WidgetsBinding.instance.addPostFrameCallback((_) {
// Code to be executed after the child widget has been built
if (!listTest.contains(testShow)) {
listTest.add(testShow);
print('***** LOADED $testShow');
}
});
return StreamBuilder(
stream: FirebaseDatabase.instance
.ref('ENTRIES/${item[KEY_ASSOC]}')
.onValue,
builder: (context, itemSnapshot) {
if (ConnectionState.waiting == itemSnapshot.connectionState) {
return const SizedBox.shrink();
} else if (itemSnapshot.hasError) {
return const ListTile(
title: Text('Error loading data'),
);
} else {
return ListTile(
title: Text('${item[KEY_ASSOC]}'),
subtitle: const SizedBox(
height: 800,
),
);
}
});
});
}
Expected Behavior
I have 4 items in the ENTRIES table. I am trying to download them pageSize at a time (ie, before the user scrolls).
As I list pageSize=2, only 2 should be loaded.
Actual Behavior
Instead, all 4 are loaded, as verified by printing the value of index when the widget in itemBuilder finishes loading.
Additional Information
For testing I've made the items artificially tall (almost as high as the screen) just to make sure that scrolling would be required to load items 3 and 4.
Is there an existing issue for this?
What plugin is this bug for?
Firebase UI Database
What platform(s) does this bug affect?
Android, iOS
List of dependencies used.
flutter pub deps -s list
Steps to reproduce
I have 4 items in the ENTRIES table. I am trying to download them pageSize at a time (ie, before the user scrolls). As I set pageSize=2, only 2 should be loaded. Instead, all 4 are loaded, as verified by printing the value of index when the widget in itemBuilder finishes loading. My theory is that this undesired behavior happens because I am calling a secondary StreamBuilder inside the itemBuilder. I need to call it in order to look up the item-associated data at another database location. In general, the query parameter doesn't seem to be doing a listen(), only a once() or get(). How to accommodate the case when a listen() is needed?
Here's the code:
Expected Behavior
I have 4 items in the ENTRIES table. I am trying to download them pageSize at a time (ie, before the user scrolls). As I list pageSize=2, only 2 should be loaded.
Actual Behavior
Instead, all 4 are loaded, as verified by printing the value of index when the widget in itemBuilder finishes loading.
Additional Information
For testing I've made the items artificially tall (almost as high as the screen) just to make sure that scrolling would be required to load items 3 and 4.