shyam rathod
shyam rathod

Reputation: 145

When add shared preference in pubspec.yml while android studio throw error?

I have used Android Studio 2024 and Flutter 3.24.3.

I am trying to install shared preferences: in Android Studio. it's a throwing error.

I don't know how to solve it.

After the comment shared preference in pubspec.yml, the project run successfully.

enter image description here

I have used Android Studio 2024 and Flutter 3.24.3.

I am trying to install shared preferences: in Android Studio. it's a throwing error.

I don't know how to solve it.

After the comment shared preference in pubspec.yml, the project run successfully.

Upvotes: 0

Views: 127

Answers (2)

shiva reddy
shiva reddy

Reputation: 25

Due to an Android Studio SDK update, this issue is appearing. Downgrade the Android SDK version, it may resolve the problem.

Upvotes: -1

Umair Ali
Umair Ali

Reputation: 836

Here are a few common solutions for shared_preferences installation issues:

  1. Add the dependency: Ensure that you've added the correct version of shared_preferences in your pubspec.yaml file:

    dependencies:
      shared_preferences: ^2.1.0  # or the latest version
    
  2. Flutter Clean: Run flutter clean and then flutter pub get to remove old builds and refresh dependencies.

  3. Check Compatibility: Make sure that the shared_preferences package version you're using is compatible with Flutter 3.24.3.

  4. Update Gradle and SDK: Ensure that your Gradle and Android SDK versions are up-to-date, as outdated versions might cause issues with dependencies like shared_preferences.

Upvotes: 0

Related Questions