【问题标题】:Flutter: Project won't compile after 'pod update'Flutter:“pod update”后项目无法编译
【发布时间】:2021-01-30 21:19:36
【问题描述】:

更新 pubspec.yaml 文件后出现错误 例如我正在尝试添加 fluttertoast:^7.1.1 pubspec.yaml 中的依赖项和 import 'package:fluttertoast/fluttertoast.dart'; 在 main.dart 中

当我运行这个项目时出错:

Running Xcode build...                                                  
Xcode build done.                                            8.4s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **


Xcode's output:
↳
    lib/main.dart:29:9: Error: No named parameter with the name 'visualDensity'.
            visualDensity: VisualDensity.adaptivePlatformDensity,
            ^^^^^^^^^^^^^
    ../../../flutter/packages/flutter/lib/src/material/theme_data.dart:201:11: Context: Found this candidate, but the arguments don't
    match.
      factory ThemeData({
              ^
    ../../../flutter/packages/flutter/lib/src/widgets/media_query.dart:126:32: Error: The getter 'physicalDepth' isn't defined for the
    class 'Window'.
     - 'Window' is from 'dart:ui'.
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'physicalDepth'.
            physicalDepth = window.physicalDepth,
                                   ^^^^^^^^^^^^^

    Command PhaseScriptExecution failed with a nonzero exit code
    note: Using new build system
    note: Planning build
    note: Constructing build description

Could not build the application for the simulator.
Error launching application on iPhone 8.

任何人都有一步一步的解决方案。

提前谢谢你。

【问题讨论】:

  • 你试过 Flutter pub get 了吗?
  • 是的,也试试
  • 看来你的实现是这里的问题。从上面的错误消息来看,您对 VisualDensity 的使用是问题所在。请尝试以下任一答案:

标签: flutter dart flutter-dependencies


【解决方案1】:

似乎 ThemeData 类没有正确加载到内存中。试试这个解决方案:

flutter clean
flutter pub cache repair
  • 右键单击控制台/错误中的 ThemeData
  • 转到C:\BACKUP\flutter\packages\flutter\lib\src\material\theme_data.dart。
  • 查找 VisualDensity 定义以查看它是否存在

如果上述方法不起作用,请尝试将以下内容添加到您的 MaterialApp:

  ThemeData(
     primarySwatch: appThemeColor,
     visualDensity: VisualDensity.adaptivePlatformDensity,
   )

【讨论】:

  • 但是一段时间后,同样的错误你有什么完整或永久的解决方案吗?
猜你喜欢
  • 2019-07-11
  • 1970-01-01
  • 2019-06-09
  • 2020-12-10
  • 2016-10-21
  • 1970-01-01
  • 2012-11-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多