Getting values from Future instances

前端 未结 2 648
野性不改
野性不改 2021-01-05 04:05

My data is something like this:

{
  \"five\": {
    \"group\": {
      \"one\": {
        \"order\": 2
      },
      \"six\": {
        \"order\": 1
      }         


        
2条回答
  •  自闭症患者
    2021-01-05 04:44

    There is no way to get back from async execution to sync execution.

    To get a value from a Future there are two ways

    pass a callback to then(...)

    theFuture.then((val) {
      print(val);
    });
    

    or use async/await for nicer syntax

    Future foo() async {
      var val = await theFuture;
      print(val);
    }
    

提交回复
热议问题