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")),
       ),
     );
 }
   }
Share:
574
void
Author by

void

Updated on December 23, 2022

Comments

  • void
    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
      JideGuru over 3 years
      add your main.dart or app code code
    • NiklasLehnfeld
      NiklasLehnfeld over 3 years
      Please add the code where you build your MaterialApp(...)