Closed dadagov125 closed 7 months ago
Latest commit: 203a7f1ef4101f3e39879423dbc811b2a1d0d655
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Hello!
I appreciate your eagerness to contribute, but this is skipping steps. Before making a PR, it is critical to first open an issue to discuss the proposed changes.
As it is, it is too early for me to review a PR, because I'm not sure I agree with the proposed API quite yet.
Do you mind opening an issue first, so we can move discussion there? I'll close this in the meantime, and we could reopen it later once this is sorted.
Ok! I'll bring this up for discussion!
Problem
In the current implementation of the application with navigation between screens, there is a need to use the same instance (e.g., state management or service) on different screens, such as
ScreenA
andScreenB
. The approach that involves creating an instance at a level aboveMaterialApp
results in the instance remaining in memory throughout the application's lifecycle, which is not optimal given its limited use.Passing data between screens via navigation arguments is limited and not always suitable for working with complex data structures or in the context of declarative navigation.
Solution
A proposed approach involves using a shared repository (
SharedInstances
) for temporarily storing and subsequently reusing instances. This repository will automatically delete unused instances, freeing up resources.Mechanism:
ScreenA
, an instance is created and registered inSharedInstances
.ScreenB
and needing to use the same instance, the provider checks for the presence of the required instance inSharedInstances
. If found, the instance is reused.ScreenA
andScreenB
are removed from the widget tree, the corresponding instance is deleted fromSharedInstances
.Advantages