英文:
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: '>=2.18.2 <3.0.0'
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 'ExtendedPagePosition.copyWith' doesn't have the named parameter 'devicePixelRatio' of overridden method 'ViewportOffset with ScrollMetrics.copyWith'.
scroll_position.dart:184
PageMetrics copyWith({
^
: Context: This is the overridden method ('copyWith').
scroll_position.dart:92
abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
^
: Error: The method 'ExtendedPagePosition.copyWith' has fewer named arguments than those of overridden method 'PageMetrics.copyWith'.
scroll_position.dart:184
PageMetrics copyWith({
^
: Context: This is the overridden method ('copyWith').
page_view.dart:277
PageMetrics copyWith({
^
: Error: The method 'ExtendedPagePosition.copyWith' doesn't have the named parameter 'devicePixelRatio' of overridden method 'PageMetrics.copyWith'.
scroll_position.dart:184
PageMetrics copyWith({
^
: Context: This is the overridden method ('copyWith').
page_view.dart:277
PageMetrics copyWith({
^
^^^^^^^^^^^
: Error: The getter 'buttonColor' isn't defined for the class 'ThemeData'.
build_color.dart:109
- 'ThemeData' is from 'package:flutter/src/material/theme_data.dart' ('../../flutter/packages/flutter/lib/src/material/theme_data.dart').
theme_data.dart:1
Try correcting the name to the name of an existing getter, or defining a getter or field named 'buttonColor'.
Color get button => Theme.of(_context).buttonColor;
^^^^^^^^^^^
: Error: Required named parameter 'devicePixelRatio' must be provided.
gesture_page_view.dart:21
final PageMetrics _testPageMetrics = PageMetrics(
^
: Context: Found this candidate, but the arguments don't match.
page_view.dart:266
PageMetrics({
^^^^^^^^^^^
: Error: The superclass, 'OneSequenceGestureRecognizer with DragGestureRecognizerMixin', has no unnamed constructor that takes no arguments.
drag.dart:145
ExtendedDragGestureRecognizer({
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: Error: Required named parameter 'devicePixelRatio' must be provided.
scroll_position.dart:192
return PageMetrics(
^
: Context: Found this candidate, but the arguments don't match.
page_view.dart:266
PageMetrics({
^^^^^^^^^^^
Target kernel_snapshot failed: Exception
…and so long.
答案1
得分: 1
你正在使用Flutter 3.10.5,但environment.sdk
显示应该是<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 <3.0.0
.
Update the pubspec.yaml
environment config:
environment:
sdk: ">=3.0.0 <4.0.0"
答案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: '>=3.0.0 <4.0.0'
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 = '1.8.22'//'1.6.10'
Eventually I flutter pub get
and compiled and run, and it works!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论