提问人:Ahmed Adel 提问时间:10/31/2023 更新时间:10/31/2023 访问量:52
在 Flutter 的 onChange 方法中,参数类型 'String' 不能分配给参数类型 'num'
The argument type 'String' can't be assigned to the parameter type 'num' in Flutter's onChange method
问:
当我尝试在我的 Cubit 的 onChange 方法中记录 Change 对象时,我在我的 Flutter 应用程序中遇到了一个错误。错误消息如下:
Error: The argument type 'String' can't be assigned to the parameter type 'num'
此错误指向我使用 log(change.toString());记录 Change 对象的行。我知道发生此错误是因为我尝试将字符串记录为 num,这在 Dart 中是不允许的。
我想了解如何在不遇到此错误的情况下正确地将 Change 对象记录为“字符串”。
下面是相关的代码片段: '''
@override
void onChange(Change<PaymentState> change) {
log(change.toString()); // Error occurs on this line
super.onChange(change);
}
我将不胜感激有关如何解决此错误并将 Change 对象正确记录为 Flutter 中的“字符串”的任何见解或建议。
答:
0赞
Cabdirashiid
10/31/2023
#1
使用喜欢debugPrint()
debugPrnt(change.toString())
将消息打印到控制台,您可以使用 “flutter” 工具的 “logs” 命令(“flutter logs”)。
Edit 是 package:flutter/src/foundation/print.dart 的一个函数。debugPrint(String?, {int? wrapWidth})
用于飞镖print(Object? object)
将对象的字符串表示形式输出到控制台。
评论
log
num
print
debugPrint
log
log
import: dart:developer
dart:math