I create new app in flutter and it's work when I run it, but when I add shared_preferences package, I got this error when I run it
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':shared_preferences:compileDebugAidl'.
> Could not resolve all task dependencies for configuration ':shared_preferences:debugCompileClasspath'.
> Could not resolve project :shared_preferences_macos.
Required by:
project :shared_preferences
> Unable to find a matching configuration of project :shared_preferences_macos:
- None of the consumable configurations have attributes.
> Could not resolve project :shared_preferences_web.
Required by:
project :shared_preferences
> Unable to find a matching configuration of project :shared_preferences_web:
- None of the consumable configurations have attributes.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 866ms
Gradle task assembleDebug failed with exit code 1
this is my pubspec.yaml
dependencies:
flutter:
sdk: flutter
shared_preferences: ^0.5.3+1
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
What is wrong with that, and how I can solve it? help me please... thanks
I was able to solve this problem by running the following command:
$ flutter pub cache repair
This issue exists
Use fix version like following as workaround, remove ^
shared_preferences: 0.5.3+1
I have tested without error
full test code
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
body: Center(
child: RaisedButton(
onPressed: _incrementCounter,
child: Text('Increment Counter'),
),
),
),
));
}
_incrementCounter() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
int counter = (prefs.getInt('counter') ?? 0) + 1;
print('Pressed $counter times.');
await prefs.setInt('counter', counter);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With