Thuta Learning
IntermediateMobile Developmentbeginner

Buttons

Relax. We'll talk through this in plain words — no textbook voice.

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.

Easy traps

  • Setting onPressed: null disables the button. If you want to attach a function, use the form onPressed: () { ... }.
Buttons | Thuta Learning