Skip to content

[Discussion] Scope spanning multiple screens #30062

@Norbert515

Description

@Norbert515

Having a way to manage scopes in Flutter.
image
(From https://proandroiddev.com/dagger-2-part-ii-custom-scopes-component-dependencies-subcomponents-697c1fa1cfc)

An example:

The login is implemented using multiple pages (which are managed by the Navigator). Each login page wants to access the LoginBloc, once the login is completed the LoginBloc is no longer needed and should be disposed.

Possible implementations right now:

  1. Nested navigators

This solves the issue as each Navigator can hold the necessary state, though this approach introduces quite a few problems because Navigators are not really intedned to be nested this way.

  1. Having the Bloc above the Navigator and only exposing them to the necessary routes

Two problems with this - nesting these dependencies can become pretty cumbersome because each route needs to be explicitly wrapped in all of the used dependencies (with dependencies I mean some kind of InheritedWidget which exposes the actual data).

And, even though other routes have no access to the data, the data is not disposed, which leads to a memory leak and leaves the bloc in an "undifined" state.

(Bloc in these examples could be replaced with any kind of business logic/ data storage)

The main problem is that each route is completely separate and there doesn't seem to be an easy way to accomplish this.

I was wondering if this is anything that should be in the framework or should be provided as a separate package.

I've talked to @rrousselGit about this, he had a few ieads how this could be solved but we'd like to hear other thoughts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: error messageError messages from the Flutter frameworkc: proposalA detailed proposal for a change to Fluttercustomer: crowdAffects or could affect many people, though not necessarily a specific customer.frameworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions