I am using Flutter.
I defined variable like this:
late Future<String?> myvariable;
I get error message saying that myvariable should be initialized.
I cannot assign a value like ‘abc’ to myvariable b/c is future string.
How do I initialize Future string variable?
Thank You
2
Answers
You can try something like this:
If you have a good default value for
myvariable
, you can use that withFuture.value
:But at that stage, I recommend just getting rid of the
Future
altogether:And then use
await
when you want to reassign a different value tomyvariable
.Also see: