gpt4 book ai didi

list - 可选参数的默认值

转载 作者:行者123 更新时间:2023-12-04 03:36:58 25 4
gpt4 key购买 nike

我有一个 future ,我希望该 future 的第一个可选参数是一个空列表。但是dartanalyzer myFile.dart返回此错误:

[error] Default values of an optional parameter must be constant
(/home/user/projects/project/lib/myFolder/myFile.dart, line 7, col 48)

我的代码:
Future<dynamic> myFuture([List<Node> content = []]) async {
/*...*/
}

我怎样才能摆脱这个错误?

最佳答案

您需要使用常量作为默认参数。要定义常量列表,您需要使用前置 const关键词:

Future<dynamic> myFuture([List<Node> content = const []]) async {
/*...*/
}

关于list - 可选参数的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31611656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com