0

I am getting an error called "Undefined name 'Provider' in flutter. Here is the code snippet for it:

addData() async {
UserProvider _userProvider = Provider.of(context, listen : false);
await _userProvider.refreshUser();}

Can someone help me figure this out?

1
  • 1
    Did you import provider at the top? Commented Jun 18, 2022 at 8:27

3 Answers 3

1

You need to import the provider package on the current page

import 'package:provider/provider.dart';
Sign up to request clarification or add additional context in comments.

Comments

1

Provider is a powerful State Management package which has to be added to the project and imported in order to use it.

If you haven't added the package, then add it by the following command in the project folder in Terminal/Command Prompt:

flutter pub add provider

Then in the file containing the snippet, import the package at the top like the following:

import 'package:provider/provider.dart';

Comments

0

Check if you have following dependency added in your pubspec.yaml file

dependencies:
  provider: ^6.0.3

If not add it or simply run in your terminal

flutter pub add provider

After getting your dependency import the provider package in your page:

import 'package:provider/provider.dart';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.