I want to execute a method after the successful execution of another method. How can I do it? Please tell me with example.
I want to execute a method after the successful execution of another method. How can I do it? Please tell me with example.
You need to make your method Asynchronous
you can use futures, async, await
Try this way
Make your first method
asyncmethod like below example
Future<int> methodOne() async {
debugPrint('first method called');
sleep(const Duration(seconds: 3));
return 4;
}
methodTwo() {
debugPrint('second method called');
}
now you can call your methods like this
GestureDetector(
onTap: () async {
await methodOne().then((value) {
methodTwo();
});
},
child: Center(child: Padding(
padding: const EdgeInsets.all(20.0),
child: Text("Click Me"),
))),
For more information please read Asynchronous programming in flutter