Richard
Richard

Reputation: 16762

Why isn't Riverpod allowing me to instantiate ProviderScope?

I'm working through the Riverpod documentation, starting with ProviderScope (from https://riverpod.dev/docs/concepts/providers). But my app isn't a function so the last line is failing. How do I fix this pleas?

const app = MaterialApp
(
    title: Messages.Ordigi,
    initialRoute: '/',
    routes: Routes.getRoutes,
);
runApp(ProviderScope(child: app()));  // ERROR: The expression doesn't evaluate to a function, so it can't be invoked

Upvotes: 0

Views: 1268

Answers (2)

Supabase Enjoyer
Supabase Enjoyer

Reputation: 370

Make sure that you added "flutter_riverpod" in your pubspec.yaml file and not just "riverpod".

This is a link to flutter_riverpod: https://pub.dev/packages/flutter_riverpod

Upvotes: 5

Josteve Adekanbi
Josteve Adekanbi

Reputation: 12673

app is a MaterialApp and not a function so you shouldn't write app()

Setting passing it directly should work, try:

const app = MaterialApp
(
    title: Messages.Ordigi,
    initialRoute: '/',
    routes: Routes.getRoutes,
);
runApp(ProviderScope(child: app));  

Upvotes: 1

Related Questions