0

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.

1 Answer 1

5

You can easily do this with await keyword:

String str = await futureString;

or with then method:

String str;

futureString.then((result){
  str = result;
});
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I got it working. The problem was that I tried to return that string, but I found a better solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.