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

Provide a way to "inject" providers into a ProviderScope/ProviderContainer #3424

Closed
iapicca opened this issue Mar 14, 2024 · 1 comment
Closed
Assignees
Labels
enhancement New feature or request needs triage

Comments

@iapicca
Copy link

iapicca commented Mar 14, 2024

use case

I initialize my app while holding the splash screen up and most importantly before runApp

code sample
void main() async {
FlutterError.demangleStackTrace = (stack) {
  if (stack is stack_trace.Trace) {
    return stack.vmTrace;
  }
  if (stack is stack_trace.Chain) {
    return stack.toTrace().vmTrace;
  }
  return stack;
};

final widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
web.usePathUrlStrategy();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);

final container = ProviderContainer();
final initializer = container.read(initializeApplicationProvider);

final result = await initializer();
if (result.isFailure) {
  exit(0);
}

widgetsBinding.scheduleAttachRootWidget(
  widgetsBinding.wrapWithDefaultView(
    ProviderScope(
      parent: container,
      child: const Application(),
    ),
  ),
);

await Future.microtask(widgetsBinding.scheduleWarmUpFrame);
FlutterNativeSplash.remove();
}

problem

ProviderScope parent will get deprecated (see issue 3261)

proposal

provide a way to inject in ProviderScope the providers from a ProviderContainer

@rrousselGit
Copy link
Owner

Use UncontrolledProviderScope here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage
Projects
None yet
Development

No branches or pull requests

2 participants