Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter ProviderNotFoundException Issue

I want use Firebase Auth in Flutter project. And I am use provider. Everything is okey but I am facing one issue with provider.

My IconButtonWidget:

class SocialIconButton extends StatelessWidget {
  final String socialIcon;
  const SocialIconButton({Key? key, required this.socialIcon})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: context.dynamicWidth(20)),
      child: IconButton(
          onPressed: (() {
            final provider =
                Provider.of<GoogleSignInProvider>(context, listen: false);
            provider.login();
          }),
          icon: Image.asset(socialIcon)),
    );
  }
}

When I press button I am facing this issue:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ProviderNotFoundException (Error: Could not find the correct Provider<GoogleSignInProvider> above this SocialIconButton Widget.

>Solution :

Wrap your App with MultiProvider and provide instance like

void main() {
  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => GoogleSignInProvider()),
      ],
      child: const MyApp(),
    ),
  );
}

More about provider. Also you can check riverpod2

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading