Md Ariful Islam

Md Ariful Islam

Md Ariful Islam

profile-pic
Flutter - Dart
Flutter - Dart

Grouping multiple functions together – ElevatedButton

August 30, 2023

Now consider the below code where inside the onpress event of the elevated button we try to call two different methods.

ElevatedButton(
onPressed: () async {
await method1();
await method2();
},
child: const Text('Click'),
),

Here in order to group these two individual methods in a single line we can wrap them using the square bracket [] as shown below ๐Ÿ‘‡ to convert them as a single list of method. This will help increase the code quality without affecting the logic.

ElevatedButton(
onPressed: () async => [await method1(), await method2()],
child: const Text('Click'),
),

Well thatโ€™s it. ๐ŸŽ‰ Run the code to see it in action.