Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ScopedPottery to provide different values to descendants in the tree #1

Closed
kaboc opened this issue Sep 25, 2023 · 0 comments · Fixed by #4
Closed

Add ScopedPottery to provide different values to descendants in the tree #1

kaboc opened this issue Sep 25, 2023 · 0 comments · Fixed by #4
Assignees
Labels
enhancement New feature or request pkg:pottery

Comments

@kaboc
Copy link
Owner

kaboc commented Sep 25, 2023

final numPot = Pot.pending<int>();
Pottery(
  pots: {
    numPot: () => 111,
  },
  builder: (context) => HomePage(),
)
class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final num1 = numPot(); // 111

    return Scaffold(
      body: ScopedPottery(
        pots: {
          numPot: () => 222,
        },
        builder: (context) {
          final num2 = numPot(); // 111
          final num3 = numPot.of(context); // 222

          return SecondPage();
        }, 
      ),
    );
  }
}

class SecondPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final num4 = numPot(); // 111
    final num5 = numPot.of(context); // 222

    return Scaffold(
      body: ScopedPottery(
        pots: {
          numPot: () => 333,
        },
        builder: (context) {
          final num6 = numPot(); // 111
          final num7 = numPot.of(context); // 333
          ...
        }, 
      ),
    );
  }
}

It is not possible to dispose of the objects in scoped pots automatically when ScopedPottery is removed from the widget tree because it is unknown which ones are disposable. Although it is possible to automatically call dispose() by checking if the pot is for ChangeNotifier (including ValueNotifier), I want to avoid it as this package is not specifically for ChangeNotifiers. Therefore ScopedPottery should have disposer to enable users to do clean-up manually.

@kaboc kaboc added the enhancement New feature or request label Sep 25, 2023
@kaboc kaboc self-assigned this Sep 25, 2023
@kaboc kaboc mentioned this issue Oct 8, 2023
@kaboc kaboc closed this as completed in #4 Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg:pottery
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant