当我在 pubspec.yaml 中添加共享首选项依赖项时,我的项目无法运行

问题描述 投票:0回答:1

当我添加 Shared_Preferences 依赖项时,我的项目无法运行

版本:最新版本2.2.0

这是错误消息:

FAILURE: Build failed with an exception.

What went wrong: A problem occurred configuring project ':shared_preferences_android'. Could not resolve all files for configuration ':shared_preferences_android:classpath'. Could not find gradle-7.2.2.jar (com.android.tools.build:gradle:7.2.2). Failed to notify project evaluation listener. Could not get unknown property 'android' for project ':shared_preferences_android' of

我在主函数中添加了

WidgetsFlutterBinding.ensureInitialized()
。当我删除依赖项时,我的问题确实得到了解决,但我需要此依赖项将令牌保存为字符串

当我删除依赖项时,我的问题确实得到了解决。

flutter dart sharedpreferences flutter-dependencies
1个回答
0
投票
  • 检查您的
    pubspec.yaml
    文件以确保您已正确添加共享首选项依赖项。它应该看起来像这样:
dependencies:
  flutter:
    sdk: flutter
  shared_preferences: ^2.2.0
  • 在项目目录中运行以下命令来获取依赖项:

    flutter pub get

  • 如果问题仍然存在:

    clean
    rebuild
    项目:

flutter clean
flutter run
  • 确保您已导入必要的包并在
    WidgetsFlutterBinding.ensureInitialized()
    函数中初始化
    main
    ,然后再使用
    shared_preferences
    将令牌保存为字符串。
© www.soinside.com 2019 - 2024. All rights reserved.