Replies: 2 comments 2 replies
-
Your consumer and provider listed here don't match. My guess is:
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Probably not related, but shouldn't _streamSub be closed at some point (in ref.onDispose for instance, in which case the instance variable is no more necessary)? e.g. @override
RideForIndexPathResult build(int section, int index) {
final db = locator.get<A18Db>();
final streamSub = db.rideForIndexPath(section, item).watchSingle().listen(onUpdate);
ref.onDispose(streamSub.close);
return RideForIndexPathResult(
rideId: 0,
title: 'Loading...',
startDate: '',
duration: 0,
distanceM: 0,
deviceId: '');
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I am experiencing an issue with a ConsumerWidget that is causing my provider to fully rebuild whenever a query returns data.
In my application, I am using Drift database to manage my data. I have several queries that I am monitoring for changes, which are used to update a grouped list view.
The first query retrieves the number of sections and the row count. The second query requires parameters, which I pass to specify a family provider. I provide the section and item index as parameters.
To display the information, I created a ConsumerWidget that takes the section and item index as parameters. This InfoCell will watch the queries via a provider that passes the provider the section and index.
The problem is that whenever the query returns data, the provider is disposed of and a new one is created. This causes the data to never be displayed, as it is stuck in a build loop.
I have attempted to identify the root cause of this issue and have found that the problem lies in the way the provider is created. The first provider does not require any parameters and does not need to be re-created when the view it is watching is not being rebuilt. However, the second provider, which also watches the other query, is created and disposed of whenever the first query returns data.
I have implemented logging in the code to verify this behavior. Every time the database stream returns an update (i.e., the first query), the provider is created anew. This is contrary to the other provider, which is also watching the other query and does not cause any issues.
I would appreciate it if you could help me identify and resolve this issue.
EDIT: I observed that when I replace the RideInfoCell with a simple Text(…) and set the ref.watch at the same level, the loop does not occur. However, I am still unable to comprehend why this behavior is happening in the RideInfoCell, as I would prefer it to occur elsewhere.
this is my provider :
the ConsumerWidget.
Beta Was this translation helpful? Give feedback.
All reactions