Provider not found exception
574
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => User())],
child: MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text("First appbar"),
),
body: Text("content")),
),
);
}
}
Author by
void
Updated on December 23, 2022Comments
-
void over 1 year
We have a cover page that has two buttons. One leads to the Contractor's login and registration page, and the other button leads to Hirer login and Registration. In order to check whether a user is already logged into the app, we are using a wrapper.dart which contains the following code:
@override Widget build(BuildContext context) { final user = Provider.of<User>(context); print(user); enter code here if (user == null) { return Authenticate(); } else { return Home(); } } }
This is our code snippet for contractorwrapper. We have a similar one for hirerWrapper as well. We are getting this error:
/flutter (23750): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter (23750): The following ProviderNotFoundException was thrown building ContractorWrapper(dirty): I/flutter (23750): Error: Could not find the correct Provider above this ContractorWrapper Widget
-
JideGuru over 3 yearsadd your main.dart or app code code
-
NiklasLehnfeld over 3 yearsPlease add the code where you build your MaterialApp(...)
-