I am trying to use a code like below:
class MultiPageProvider extends StatefulWidget {
const MultiPageProvider({Key? key}) : super(key: key);
@override
_MultiPageProviderState createState() => _MultiPageProviderState();
}
class _MultiPageProviderState extends State<MultiPageProvider> {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<UserModal>(
create: (context) => UserModal(),
child: Scaffold(
appBar: AppBar(
title: const Text(
"Using Provider",
),
),
body: Consumer<UserModal>(
builder: (context, modal, child) {
switch (modal.activeIndex) {
case 0:
return const BasicDetails();
case 1:
return const EducationDetails();
default:
return const BasicDetails();
}
},
),
),
);
}
}
But as long as I use all the providers inside the main.dart
function like below, I am wondering to know how can I add this provider to main.dart
like the others?
class MyApp extends StatelessWidget { const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider.value(
value: Auth(),
),
ChangeNotifierProxyProvider<Auth, Books>(
create: (ctx) => Books('', []),
update: (ctx, auth, previousBooks) => Books(
auth.userId,
previousBooks == null ? [] : previousBooks.books,
),
),
],
};
}