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

Overriden providers are not passed to dialogs or modals #3591

Closed
tomasweigenast opened this issue Jun 3, 2024 · 5 comments
Closed

Overriden providers are not passed to dialogs or modals #3591

tomasweigenast opened this issue Jun 3, 2024 · 5 comments
Assignees
Labels
bug Something isn't working needs triage

Comments

@tomasweigenast
Copy link

tomasweigenast commented Jun 3, 2024

I have a problem when I want to override a provider and pass them to a bottom sheet.

Here the provider is overridden:

Widget build(BuildContext context, WidgetRef ref) {
    final business = ref.watch(fetchBusinessProvider(businessCustomId, locationId: locationId));
    return switch (business) {
      AsyncError(:final error, :final stackTrace) => ErrorDisplay(error: error, stackTrace: stackTrace),
      AsyncData(:final value) => ProviderScope(
          // parent: ProviderScope.containerOf(context),
          overrides: [
            currentBusinessControllerProvider.overrideWith(() => CurrentBusinessController.override(value)),
          ],
          child: const _BusinessView(),
        ),
      _ => const LoadingIndicator(),
    };
  }

NOTE: I tried adding the parent property but it did not work

_BusinessView is just another widget so the override works.
I have a widget called _ItemsList, which renders inside _BusinessView, and in the build method of the _ItemsList widget I have:

print("Exists here: ${ProviderScope.containerOf(context).exists(currentBusinessControllerProvider)}");

Which prints:
Exists here: true

_ItemsList just contains a bunch of items, that, when clicked:

final parentContainer = ProviderScope.containerOf(context);
showModalBottomSheet(
                context: context,
                isScrollControlled: true,
                builder: (context) => ProviderScope(
                  // parent: parentContainer,
                  overrides: [
                       // this can safely be ignored, I don't think this causes any problem
                       currentBasketItemProvider.overrideWithValue(BasketItem.fromProduct(product)),
                  ],
                  child: const ProductSheet(),
                ),
              );

NOTE: Again, I tried passing the parent but no solution

And, inside ProductSheet:

@override
  Widget build(BuildContext context, WidgetRef ref) {
    print("Exists in ProductSheet: ${ref.exists(currentBusinessControllerProvider)}");
    
    ...
}

Which prints: Exists in ProductSheet: false.

@rrousselGit
Copy link
Owner

That's normal. Modals are in a different part of the widget tree. They don't have access to the same InehritedWidgets.

Try using parent (although it's flawed, as described in a different issue) or use OverlayPortal

@tomasweigenast
Copy link
Author

I tried using parent as my notes say. I doesn't work @rrousselGit

@tomasweigenast
Copy link
Author

Please re-open because using parent does not solve the issue

@rrousselGit
Copy link
Owner

You should specifically explain why parent doesn't work. Saying that it doesn't work isn't enough information.

@tomasweigenast
Copy link
Author

Well, I don't know why parent doesn't work. Adding parent or removing it executes the same way. What do you need to know?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants