I'm still pretty new to Dart and the syntax of => (fat arrow) still confuses me (I come from C# background).
So in C# fat arrow ( => ) says: goes to so for example:
Action<string> action1 = (str) => { System.Diagnostic.Debug.WriteLine("Parameter received: " + str.ToString()); }
action1("Some parameter");
意思:无论作为参数发送到action1
(如果它可以强制转换为string
)goes to内部作用域(在我们的例子中,它只打印在Debug.WriteLine()
中
但在dart 里就不一样了.(?)
例如,在Future.then
ClassWithFutures myClass = new ClassWithFutures();
myClass.loadedFuture.then(
(str) => { print("Class was loaded with info: $str"),
onError: (exp) => { print("Error occurred in class loading. Error is: $exp"); }
);
Dart editor警告我,第一个和第二个print
是:Expected string literal for map entry key
.我认为以C#的方式,str
只是参数的名称,它将由Future.then
用来调用onValue
或onError
的内部回调来填充
我做错了什么?