如何在`flutter upgrade`后使我的Flutter项目正常运行?

huangapple go评论75阅读模式
英文:

How to make my flutter up and running after a `flutter upgrade`?

问题

我解决了我遇到的依赖问题。

但是现在,在尝试运行项目时,我收到了所有这些错误,似乎是来自Flutter库本身的。


environment:
  sdk: '>=2.18.2 <3.0.0'

我的版本:

$ flutter --version
Flutter 3.10.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 796c8ef792(8天前)• 2023-06-13 15:51:02 -0700
Engine • revision 45f6e00911
Tools • Dart 3.0.5 • DevTools 2.23.1

以及flutter doctor

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter(通道稳定,3.10.5,在macOS 12.6.2 21G320 darwin-x64上,区域设置为fr-FR)
[✓] Android工具链 - 用于开发Android设备(Android SDK版本31.0.0)
[✓] Xcode - 用于iOS和macOS的开发(Xcode 14.2)
[✓] Chrome - 用于Web开发
[✓] Android Studio(版本2021.1)
[✓] VS Code(版本1.79.1)
[✓] 已连接设备(3个可用)
[✓] 网络资源

• 没有发现问题!

我运行了:

flutter clean
flutter pub get

但没有改善情况。

这是报告的第一个错误。我应该怎么办?

在Pixel 7上以调试模式启动lib/main.dart...
main.dart:1
: 错误:方法'ExtendedPagePosition.copyWith'没有覆盖方法'ViewportOffset with ScrollMetrics.copyWith'的命名参数'devicePixelRatio'。
scroll_position.dart:184
  PageMetrics copyWith({
              ^
: 上下文:这是被覆盖的方法('copyWith')。
scroll_position.dart:92
abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
               ^
: 错误:方法'ExtendedPagePosition.copyWith'的命名参数少于被覆盖方法'PageMetrics.copyWith'的参数。
scroll_position.dart:184

  PageMetrics copyWith({
              ^
: 上下文:这是被覆盖的方法('copyWith')。
page_view.dart:277
  PageMetrics copyWith({
              ^
: 错误:方法'ExtendedPagePosition.copyWith'没有覆盖方法'PageMetrics.copyWith'的命名参数'devicePixelRatio'。
scroll_position.dart:184
  PageMetrics copyWith({

              ^
: 上下文:这是被覆盖的方法('copyWith')。
page_view.dart:277
  PageMetrics copyWith({
              ^
                                         ^^^^^^^^^^^
: 错误:类'ThemeData'没有定义'buttonColor'的获取器。
build_color.dart:109
- 'ThemeData' 来自 'package:flutter/src/material/theme_data.dart'('../../flutter/packages/flutter/lib/src/material/theme_data.dart')。
theme_data.dart:1
尝试更正名称以匹配现有获取器的名称,或定义一个名为'buttonColor'的获取器或字段。
  Color get button => Theme.of(_context).buttonColor;
                                         ^^^^^^^^^^^

: 错误:必须提供必需的命名参数'devicePixelRatio'。
gesture_page_view.dart:21
final PageMetrics _testPageMetrics = PageMetrics(
                                                ^
: 上下文:找到了这个候选项,但参数不匹配。
page_view.dart:266
  PageMetrics({
  ^^^^^^^^^^^
: 错误:超类'OneSequenceGestureRecognizer with DragGestureRecognizerMixin'没有不带参数的无名构造函数。
drag.dart:145
  ExtendedDragGestureRecognizer({
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: 错误:必须提供必需的命名参数'devicePixelRatio'。
scroll_position.dart:192
    return PageMetrics(
                      ^
: 上下文:找到了这个候选项,但参数不匹配。
page_view.dart:266
  PageMetrics({

  ^^^^^^^^^^^
目标kernel_snapshot失败:异常

...如此长。

英文:

I solved the dependency issues I had.

But now, when trying to run the project I get all those errors that seem to come from Flutter libs themselves.


environment:
  sdk: &#39;&gt;=2.18.2 &lt;3.0.0&#39;

My version:

$ flutter --version
Flutter 3.10.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 796c8ef792 (8 days ago) • 2023-06-13 15:51:02 -0700
Engine • revision 45f6e00911
Tools • Dart 3.0.5 • DevTools 2.23.1

And the flutter doctor:

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.5, on macOS 12.6.2 21G320 darwin-x64, locale fr-FR)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.79.1)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

I ran:

flutter clean
flutter pub get

without any improvement about the situation.

Here are the first error reported. What should I do?

Launching lib/main.dart on Pixel 7 in debug mode...
main.dart:1
: Error: The method &#39;ExtendedPagePosition.copyWith&#39; doesn&#39;t have the named parameter &#39;devicePixelRatio&#39; of overridden method &#39;ViewportOffset with ScrollMetrics.copyWith&#39;.
scroll_position.dart:184
  PageMetrics copyWith({
              ^
: Context: This is the overridden method (&#39;copyWith&#39;).
scroll_position.dart:92
abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
               ^
: Error: The method &#39;ExtendedPagePosition.copyWith&#39; has fewer named arguments than those of overridden method &#39;PageMetrics.copyWith&#39;.
scroll_position.dart:184

  PageMetrics copyWith({
              ^
: Context: This is the overridden method (&#39;copyWith&#39;).
page_view.dart:277
  PageMetrics copyWith({
              ^
: Error: The method &#39;ExtendedPagePosition.copyWith&#39; doesn&#39;t have the named parameter &#39;devicePixelRatio&#39; of overridden method &#39;PageMetrics.copyWith&#39;.
scroll_position.dart:184
  PageMetrics copyWith({

              ^
: Context: This is the overridden method (&#39;copyWith&#39;).
page_view.dart:277
  PageMetrics copyWith({
              ^
                                         ^^^^^^^^^^^
: Error: The getter &#39;buttonColor&#39; isn&#39;t defined for the class &#39;ThemeData&#39;.
build_color.dart:109
- &#39;ThemeData&#39; is from &#39;package:flutter/src/material/theme_data.dart&#39; (&#39;../../flutter/packages/flutter/lib/src/material/theme_data.dart&#39;).
theme_data.dart:1
Try correcting the name to the name of an existing getter, or defining a getter or field named &#39;buttonColor&#39;.
  Color get button =&gt; Theme.of(_context).buttonColor;
                                         ^^^^^^^^^^^

: Error: Required named parameter &#39;devicePixelRatio&#39; must be provided.
gesture_page_view.dart:21
final PageMetrics _testPageMetrics = PageMetrics(
                                                ^
: Context: Found this candidate, but the arguments don&#39;t match.
page_view.dart:266
  PageMetrics({
  ^^^^^^^^^^^
: Error: The superclass, &#39;OneSequenceGestureRecognizer with DragGestureRecognizerMixin&#39;, has no unnamed constructor that takes no arguments.
drag.dart:145
  ExtendedDragGestureRecognizer({
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: Error: Required named parameter &#39;devicePixelRatio&#39; must be provided.
scroll_position.dart:192
    return PageMetrics(
                      ^
: Context: Found this candidate, but the arguments don&#39;t match.
page_view.dart:266
  PageMetrics({

  ^^^^^^^^^^^
Target kernel_snapshot failed: Exception

…and so long.

答案1

得分: 1

你正在使用Flutter 3.10.5,但environment.sdk显示应该是&lt;3.0.0

请更新pubspec.yaml中的环境配置:

environment:
  sdk: ">=3.0.0 <4.0.0"
英文:

You're using Flutter 3.10.5, but environment.sdk says it should be &lt;3.0.0.

Update the pubspec.yaml environment config:

environment:
  sdk: &quot;&gt;=3.0.0 &lt;4.0.0&quot;

答案2

得分: -1

我更改了SDK,按照@lluchkaa的建议:

environment:
  sdk: '>=3.0.0 <4.0.0'

然后,我执行了清理操作:

$ flutter clean

接着,我升级了Dart:

$ dart pub upgrade

最后,我通过将Kotlin版本升级到最新稳定版来升级了我的gradle(文件android/build.gradle):

buildscript {
    ext.kotlin_version = '1.8.22'// '1.6.10'

最后,我运行了flutter pub get编译并运行,一切正常!

英文:

Following up @lluchkaa idea, I changed the sdk:

environment:
  sdk: &#39;&gt;=3.0.0 &lt;4.0.0&#39;

And, I did clean with:

$ flutter clean

Then I upgraded Dart with:

$ dart pub upgrade

And, finally, I upgraded my gradle, by bumping Kotlin version to the last stable as follows (file android/build.gradle):

buildscript {
    ext.kotlin_version = &#39;1.8.22&#39;//&#39;1.6.10&#39;

Eventually I flutter pub getand compiled and run, and it works!

huangapple
  • 本文由 发表于 2023年6月22日 05:08:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76527143.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定