Dart 中用于非参数方法的 then() 语法

then() syntax in Dart for non argument methods

我有两种方法可以执行。我想执行 method1() 然后 method2()。这两个方法没有任何参数只有一些条件那么我的代码的语法是什么?

Future method1() {
  //Something;
}

Future method2() {
  //Somthing;
}

method() {
  //Execute [Method1] then [Method2]
}

您可以将 method 标记为 async 以执行以下操作:

Future method() async {
  await method1();
  return method2(); // or await method2();
}

或者像这样使用then()

Future method() => method1().then((_) => method2());