我在 flutter 中创建了新应用程序,运行它时它可以工作,但是当我添加 shared_preferences 包时,运行它时出现此错误
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
Run Code Online (Sandbox Code Playgroud)
这是我的 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
Run Code Online (Sandbox Code Playgroud)
这有什么问题,我该如何解决?请帮帮我...谢谢
存在此问题
使用如下修复版本作为解决方法,删除^
共享首选项:0.5.3+1
我测试过没有错误
完整的测试代码
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);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10015 次 |
最近记录: |