I just started using provider as a state management for flutter. I have a value in a provider to be used for the initial login. isLogin will return true or false and depending on that it will redirect the user to home or login page. I'm getting the error below:
Could not find the correct Provider above this MyApp Widget
Plus, is this a good way of doing authentication or is there a better way. I'm using laravel API for authentication.
Main.dart
void main() {
runApp(MyApp());
}
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<UserProvider>(
create: (context) => UserProvider(),
child: MaterialApp(
initialRoute:Provider.of<UserProvider>(context,listen:false).isLogin?'/':'/login',
routes: {
'/':(_)=>HomePage(),
'/donation-history':(_)=>DonationHistoryPage(),
'/login':(_)=>LoginPage(),
'/new-donation':(_)=>NewDonation()
},
debugShowCheckedModeBanner:false,
title: 'RedHero',
theme: ThemeData(
primaryColor: kPrimaryColor,
accentColor: Colors.white,
scaffoldBackgroundColor: kBackgroundColor,
fontFamily: "Poppins",
textTheme: TextTheme(
bodyText1: TextStyle(color: kBodyTextColor)
)
),
),
);
}