【问题标题】:Problem buliding old project with flutter 2.0.0使用颤振 2.0.0 构建旧项目的问题
【发布时间】:2021-06-02 20:52:56
【问题描述】:

升级到 Flutter 2.0.0 后,我无法再构建应用程序了。这是输出。我的问题是我大量使用库,其中很多不是空安全的,我无法将所有依赖项升级到空安全模式。有人对此有什么建议吗?

Try calling using ?. instead.
    ).replaceFirst(r'$remainingCount', formatDecimal(remainingCount));
      ^^^^^^^^^^^^
../../flutter/flutter/.pub-cache/hosted/pub.dartlang.org/extended_image-1.6.0/lib/src/extended_image.dart:785:44: Error: No named parameter with the name 'nullOk'.
    _invertColors = MediaQuery.of(context, nullOk: true)?.invertColors ??
                                           ^^^^^^
../../flutter/flutter/packages/flutter/lib/src/widgets/media_query.dart:818:25: Context: Found this candidate, but the arguments don't match.
  static MediaQueryData of(BuildContext context) {

                        ^^
../../flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_svg-0.18.1/lib/src/picture_provider.dart:50:59: Error: No named parameter with the name 'nullOk'.
        context != null ? Localizations.localeOf(context, nullOk: true) : null,
                                                          ^^^^^^
../../flutter/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: Context: Found this candidate, but the arguments don't match.
  static Locale localeOf(BuildContext context) {

                ^^^^^^^^

更新1:更新到flutter 2.0.1和flutter pub cache repairflutter clean之后。并使用标志flutter run --no-sound-null-safety 运行。仍然没有机会运行应用程序,这是输出。

../../flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_neumorphic-3.0.3/lib/src/widget/app_bar.dart:147:57: Error: No named parameter with the name 'nullOk'.
    final ScaffoldState scaffold = Scaffold.of(context, nullOk: true);
                                                        ^^^^^^
../../flutter/flutter/packages/flutter/lib/src/material/scaffold.dart:1944:24: Context: Found this candidate, but the arguments don't match.
  static ScaffoldState of(BuildContext context) {
                       ^^
../../flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_svg-0.19.1/lib/src/picture_provider.dart:52:59: Error: No named parameter with the name 'nullOk'.     
        context != null ? Localizations.localeOf(context, nullOk: true) : null,
                                                          ^^^^^^
../../flutter/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: Context: Found this candidate, but the arguments don't match.
  static Locale localeOf(BuildContext context) {
                ^^^^^^^^


FAILURE: Build failed with an exception.

* Where:
Script 'D:\Documents\flutter\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\Documents\flutter\flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* 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 26s

更新2:这是flutter doctor的输出

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.1, on Microsoft Windows [Version 10.0.19042.804], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.4)   
[√] Android Studio (version 4.1.0)
[√] IntelliJ IDEA Ultimate Edition (version 2020.3)
[√] VS Code (version 1.54.1)
[√] Connected device (4 available)

• No issues found!

【问题讨论】:

  • 解决了吗?
  • 不,我目前正在使用 Flutter 1.22.6 来构建我的项目,直到所有依赖项都迁移到 null 安全性,然后查看新的 Flutter 是否有效。
  • 这里一样,我也切换到1.22
  • 有关于这个问题的消息吗?
  • 不,很遗憾,由于我的项目的某些包仍未迁移到 null 安全性,我仍在使用 1.22.6 版本的颤振。

标签: flutter dart-null-safety


【解决方案1】:

您仍然可以使用 Flutter 2.0 忽略 null 安全迁移。在你的pubspec.yaml中设置这个sdk约束版本

environment:
  sdk: ">=2.7.0 <3.0.0"

【讨论】:

  • 是的,我知道,我从未更新过我项目的 dart SDK。我仍然无法构建
  • 我遇到了同样的问题,通过将 SDK 设置为 ">=2.7.0 解决了这个问题
【解决方案2】:
flutter clean

flutter pub get

应该可以解决你的问题。

【讨论】:

    猜你喜欢
    • 2022-11-12
    • 2021-05-27
    • 2022-08-17
    • 2018-08-21
    • 2021-09-26
    • 1970-01-01
    • 2022-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多