2017-07-04 62 views
3

我收到以下错误。 The argument type 'dynamic' can't be assigned to the parameter type '() -> dynamic' 的示例是:镖强模式:匿名函数返回错误

outerFunc(somevar) { 
    return() {....} 
} 
anOtherFunction(func()) {....} 

anOtherFunction(outerFunc('test')); 

这些当我在analysis_options.yaml返回一个匿名函数,在强模式下发生。

strong-mode: 
    implicit-casts: false 
+0

添加自己的类型解决了这个问题'typedef的功能funcType();'然后使用它像'anOtherFunction(outerFunc( '测试' )as funcType);' – fredtma

回答

1

outerFunc没有指定返回类型,因此dynamic假设。 您可以创建一个typedef并将其用作outerFunc的返回类型。 函数类型不能从return语句中推断出来。

typedef dynamic F(); 

F outerFunc(somevar) { 
    return() {}; 
} 

你也可以写函数类型在线

dynamic Function() outerFunc(somevar) { 
    return() {}; 
} 
+1

谢谢,我走了这条路 – fredtma