You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a basic Bluetooth app. At the moment there is a scanning screen, which lets the user select a device to connect to. Upon selection, a loading screen is showed, some information are downloaded from the Bluetooth device and finally the main page is shown, which contains the downloaded information. This information can be updated throughout the app, thus I need it to be represented by a Notifier. Here is the problem tho: If I update the information using the information with the read method, then I load the widget which watches the Notifier, the information is not updated. If I call read using, for example, a button after the widget watching the notifier is shown, it is updated correctly. It seems to me that I need to pass some kind of initialization value to the notifier, but it incredibly annoying to do so and it's frown upon I seem to understand. The only way that seems to work is to pass the initialization value to the build method of the notifier. This works, but now every time I call the provider is have to pass the initialization value, otherwise it doesn't work, which means passing down this value to the widget tree completely defeating the purpose of using Riverpod.
Is there really no way to achieve what I'm trying to do? It seems pretty natural to me showing a Widget after some state have been set, but it doesn't seem to work. I'm forced to show a screen with null values until they are updated, which is stupid.
EDIT: I was able to make it work by calling the watch method in the build method of the parent Widget of the loading screen and the main page containing the information to show. Is this intended behavior? I'm not even using the value I watch, I just watch to forcefully have it loaded by the time the child Widget is build.
EDIT2: great, now the entire app rebuilds when I update the value because the watch call is so far above the tree. I basically need to completely refactor the way a handle the connection states and loading screen to have the watch a low in the widget tree as possible, while still being before the final widget showing the information is called.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a basic Bluetooth app. At the moment there is a scanning screen, which lets the user select a device to connect to. Upon selection, a loading screen is showed, some information are downloaded from the Bluetooth device and finally the main page is shown, which contains the downloaded information. This information can be updated throughout the app, thus I need it to be represented by a Notifier. Here is the problem tho: If I update the information using the information with the
read
method, then I load the widget whichwatch
es the Notifier, the information is not updated. If I callread
using, for example, a button after the widgetwatch
ing the notifier is shown, it is updated correctly. It seems to me that I need to pass some kind of initialization value to the notifier, but it incredibly annoying to do so and it's frown upon I seem to understand. The only way that seems to work is to pass the initialization value to thebuild
method of the notifier. This works, but now every time I call the provider is have to pass the initialization value, otherwise it doesn't work, which means passing down this value to the widget tree completely defeating the purpose of using Riverpod.Is there really no way to achieve what I'm trying to do? It seems pretty natural to me showing a Widget after some state have been set, but it doesn't seem to work. I'm forced to show a screen with
null
values until they are updated, which is stupid.EDIT: I was able to make it work by calling the
watch
method in the build method of the parent Widget of the loading screen and the main page containing the information to show. Is this intended behavior? I'm not even using the value I watch, I just watch to forcefully have it loaded by the time the child Widget is build.EDIT2: great, now the entire app rebuilds when I update the value because the
watch
call is so far above the tree. I basically need to completely refactor the way a handle the connection states and loading screen to have the watch a low in the widget tree as possible, while still being before the final widget showing the information is called.EDIT3: I think I find a way to solve it. Stackoverflow with my own answer to this problem.
Beta Was this translation helpful? Give feedback.
All reactions