【发布时间】:2014-08-19 18:17:02
【问题描述】:
我将以下代码作为匿名函数(也是函数字面量或 lambda 抽象),用于DART mailer
email(){
...
emailTransport.send(envelope)
.then((success) => print('Email sent! $success'))
.catchError((e) => print('Error occured: $e'));
}
这很好,但我需要用“return”替换“print”,如下所示:
email(){
...
emailTransport.send(envelope)
.then((success) => return 'Email sent! $success')
.catchError((e) => return 'Error occured: $e');
}
但是失败了,返回没有被识别!
我尝试了下面的代码,但也失败了。
email(){
...
var msg;
...
emailTransport.send(envelope)
.then((success) => msg = 'Email sent! $success')
.catchError((e) => msg = 'Error occured: $e');
return msg;
}
但“msg”仍然为 NULL!
任何想法。
【问题讨论】:
标签: nested dart mailer nested-function