【发布时间】:2021-05-13 00:51:32
【问题描述】:
我正在分配Function(String) 类型的变量stringFn,例如:
Function(String) stringFn = (String? s) {};
即使为stringFn 分配了一个可以接收可为空参数的函数,dart 静态类型检查也不会出错。
打印 stringFn 的 runtimeType 会导致 (String?) => Null 但如果我调用该函数:
stringFn(null);
导致The argument type 'Null' can't be assigned to the parameter type 'String' 我同意,因为该类型不允许可空参数。
我在这里错过了什么吗?
【问题讨论】:
标签: flutter dart dart-null-safety