Search code examples
flutterfirebasedartfirebase-authenticationflutter-dependencies

Error in provider flutter context listen:false


So, I'm making an app of OTP login with flutter and dart and when I provide the pohone number it's shows an error

The code is this:

 void sendPhoneNumber() {
    final ap = Provider.of<AuthProvider>(context, listen: false);
    String phoneNumber = phoneController.text.trim();
    ap.signInWithPhone(context, "+{selectedCountry.phoneCode}$phoneNumber");
  }

The error it's when I'm in final ap, there shows this: "Tried to listen to a value exposed with provider, from outside of the widget tree."

Any idea what can i do to solve it?


Solution

  • Seem like you're forgetting to create an object

    Single

    Provider(
      create: (_) => MyModel(),
      child: ...
    )
    

    Multi

        runApp(
                MultiProvider(
                  providers: [
                    ChangeNotifierProvider(create: (context) => myViewModel()),
                           ]
                          )