Vincent Guttmann
Vincent Guttmann

Reputation: 293

How to convert Future<String> to String

I'm writing an app that needs to load results from a file when it starts, so time consumption is not really an issue here.

Because I don't want the whole code to be asynchronous (because I want everything to be still pretty easy to understand), I'm looking for a way to convert a Future<String > into a normal String.

I would like help at any level: If anyone knows a way to load file contents without asynchronous code, that would also be good.

Upvotes: 0

Views: 3422

Answers (1)

konstantin_doncov
konstantin_doncov

Reputation: 2879

You can easily do this with await keyword:

String str = await futureString;

or with then method:

String str;

futureString.then((result){
  str = result;
});

Upvotes: 5

Related Questions