如何在Dart中从Future <String>派生字符串

时间:2019-12-02 15:34:31

标签: flutter dart

我希望获取一个字符串,以便从下面的异步函数传递到flutter中的第二个活动:

Future<String> getString() async {
    return await readFromFile("./abc.txt").toString();

}

我的问题是从上面的函数中获取一个字符串,并在onPressed()函数中使用它,我想导航到下一页,并希望将字符串传递到下一页。 每当我尝试执行此操作时,它都会给我类似“将来的实例...”的信息,而不是实际的字符串。

1 个答案:

答案 0 :(得分:0)

您可以拆分分配或添加括号,因为现在您实际上尝试在<script> import ImageButton from './components/ImageButton.svelte'; let imgUrl = "/images/test.png"; </script> <style> .my-image-button{ border: 1px solid white; } </style> <ImageButton imageUrl={imgUrl} cssClass="my-image-button" /> await

toString
Future<String> getString() async {
  Something content = await readFromFile("./abc.txt");
  return content.toString();
}