A button is the doorway that lets user actions into your app. Flutter offers several button types: ElevatedButton, TextButton, OutlinedButton, and IconButton. The most important part of making a button work is its onPressed callback. Without onPressed, the button becomes disabled.
dart
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
print('Primary action clicked');
},
child: const Text('Save'),
),
TextButton(
onPressed: () {
print('Secondary action clicked');
},
child: const Text('Cancel'),
),
],
)You should see
Two buttons, Save and Cancel, appear, and tapping each one prints the corresponding message to the debug console.What's Next
Next, learn about GestureDetector, which lets you make even non-button widgets tappable.