Error: 类 ‘RouteSettings’ 没有定义 ‘copyWith’ 方法。

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

Error: The method 'copyWith' isn't defined for the class 'RouteSettings'

问题

我正在尝试运行ThingsBoard发布的Flutter示例,该示例在此入门指南中提供。

示例代码:https://github.com/thingsboard/flutter_thingsboard_app

当我在VS Code中运行启动调试时,出现以下错误:

Launching lib\main.dart on Android SDK built for x86 in debug mode...
/C:/src/flutter/.pub-cache/hosted/pub.dev/fluro-2.0.3/lib/src/fluro_router.dart:134:37: Error: The method 'copyWith' isn't defined for the class 'RouteSettings'.
- 'RouteSettings' is from 'package:flutter/src/widgets/navigator.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/navigator.dart').
Try correcting the name to the name of an existing method, or defining a method named 'copyWith'.
      settingsToUse = settingsToUse.copyWith(name: path);
                                    ^^^^^^^^

Target kernel_snapshot failed: Exception

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1151

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)

* 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 2m 8s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

我是移动应用程序的新手,请帮助我,我应该怎么办?

我想通过VS Code运行这个示例。

英文:

I'm trying to run a sample of flutter , that thingsboard.io published in this starting guide.
sample code : https://github.com/thingsboard/flutter_thingsboard_app

when i run start debuging in VS Code, i get this error:

Launching lib\main.dart on Android SDK built for x86 in debug mode...
/C:/src/flutter/.pub-cache/hosted/pub.dev/fluro-2.0.3/lib/src/fluro_router.dart:134:37: Error: The method 'copyWith' isn't defined for the class 'RouteSettings'.
- 'RouteSettings' is from 'package:flutter/src/widgets/navigator.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/navigator.dart').
Try correcting the name to the name of an existing method, or defining a method named 'copyWith'.
      settingsToUse = settingsToUse.copyWith(name: path);
                                    ^^^^^^^^

Target kernel_snapshot failed: Exception

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1151

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)

* 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 2m 8s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

i'm newborn in mobile application, please help me, what should i do?

i want run this sample by VS code.

答案1

得分: 2

尝试运行 flutter pub upgrade。我遇到了同样的问题,它有效。

英文:

Try to run flutter pub upgrade. I
was facing the same problem and it worked

答案2

得分: 1

RouteSettings.copyWith已被移除。

只需使用:

从:

RouteSettings newSettings = oldSettings.copyWith(name: 'new name');

到:

RouteSettings newSettings = RouteSettings(name: 'new name', arguments: oldSettings.arguments);
英文:

RouteSettings.copyWith was removed.

Just use

From:

RouteSettings newSettings = oldSettings.copyWith(name: 'new name');

To:

RouteSettings newSettings = RouteSettings(name: 'new name', arguments: oldSettings.arguments);

huangapple
  • 本文由 发表于 2023年2月19日 01:39:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75495189.html
匿名

发表评论

匿名网友

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

确定