Reputation: 79
I have following class.
class Element {
Future<Element> findById(var id)async {
await networkRequest();
return this;
}
Futute<Element> click() async {
await networkRequest();
return this;
}
}
I want to achieve the something like.
main() async {
var element = Element();
await element.findyById("something").click();
}
But I'm not able to do so because element.findById() returns future. How can I chain these async methods.
Upvotes: 1
Views: 671
Reputation: 34281
While there's no special syntax to chain futures, there are two semantically equivalent ways to do what you want:
1) Two separate await
calls:
await element.findById("something");
await click();
2) Chaining with then
:
await element.findById("something").then(() => click());
Upvotes: 2
Reputation: 11210
final el = await element.findyById("something");
await el.click();
Upvotes: 0