【发布时间】:2020-10-22 19:37:44
【问题描述】:
这是我一直在尝试的代码。我想使用extractInfo() 方法返回String。
我们如何返回String,因为参数不接受String以外的任何其他参数
Future<String> info(String x) a sync{
final translator = Google Translator();
return await translator.translate(x, to: 'en');
}
String y;
String extract Info(){
String x = "Title :${widget.userPosts[widget.index].title}\n"
"User Id :${widget.userPosts[widget.index].userId}\n"
"Id :${widget.userPosts[widget.index].id}\n"
"Completed :${widget.userPosts[widget.index].completed}\n";
info(x).then((value) => y = value);
print(y);
return x;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("More"),
),
body: StoryView(
storyItems: [
StoryItem.text(
title: extractInfo(),
backgroundColor: Colors.redAccent,
)
],
onStoryShow: (s) {
print("Showing a story");
},
onComplete: () {
print("Completed a cycle");
},
progressPosition: ProgressPosition.top,
repeat: false,
controller: story Controller,
),`
);
}
【问题讨论】:
标签: flutter dart translation