I want to declare a variable that receives the result of asynchronous function.
var eff_histo= await _eff_histo(selectedline);
The await expression can only be used in an asynchronous function
I want to declare a variable that receives the result of asynchronous function.
var eff_histo= await _eff_histo(selectedline);
The await expression can only be used in an asynchronous function
You still are misunderstanding async
. The async
keyword does not mean "run on another thread".
To push some code onto another thread, you need to do it explicitly, e.g., Task.Run
:
await Task.Run(() => Logger.LogInfo("Pushing new call {0} with {1} id".Fill(callNotificationInfo.CallerId));
I have an async
/await
intro post that you may find helpful.
I think this is more of a philosophy that a synchronous method should not wait because other important tasks may be affected, time taking async tasks however can take their time thus await makes sense there. Look into this for more information https://github.com/dart-lang/sdk/issues/22269#issuecomment-108458526
you can't used await outside async function ,, try to build your varable localy and declare your varable inside initState
var eff_histo;
@override
void initState() async {
super.initState()
eff_histo= await _eff_histo(selectedline);
}