Learn/Core Widgets/Buttons & Input

Buttons & Input

Interactive widgets for user input

5 min~5 min read+30 FX

You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.

Table of Contents

  1. 1. Styling Buttons
  2. 2. Action Hierarchy For Better UX
  3. 3. This Lesson In Simple Words
  4. 4. Your level focus
  5. 5. One practical habit
  6. 6. Deep Understanding Guide
  7. 7. Why this lesson matters
  8. 8. Study flow for better retention
  9. 9. Quick Glossary

Having trouble? AI is here to help

Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.

Use the AI button at the bottom of the screen

Button Widgets

Flutter provides several built-in button types, each designed for a different level of visual emphasis. Choosing the right button helps users understand the importance of each action.

dart
1// ElevatedButton - Primary action (filled)
2ElevatedButton(
3 onPressed: () {
4 print('Clicked!');
5 },
6 child: Text('Sign Up'),
7)
8
9// TextButton - Low emphasis (no background)
10TextButton(
11 onPressed: () {},
12 child: Text('Learn More'),
13)
14
15// OutlinedButton - Medium emphasis (border only)
16OutlinedButton(
17 onPressed: () {},
18 child: Text('Cancel'),
19)
20
21// IconButton - Icon only
22IconButton(
23 icon: Icon(Icons.favorite),
24 onPressed: () {},
25)
26
27// FloatingActionButton - Main action
28FloatingActionButton(
29 onPressed: () {},
30 child: Icon(Icons.add),
31)

Styling Buttons

You can customize the appearance of any Flutter button using the styleFrom method. This gives you control over background color, text color, padding, and shape.

dart
1ElevatedButton(
2 onPressed: () {},
3 style: ElevatedButton.styleFrom(
4 backgroundColor: Colors.blue,
5 foregroundColor: Colors.white,
6 padding: EdgeInsets.symmetric(horizontal: 32, vertical: 16),
7 shape: RoundedRectangleBorder(
8 borderRadius: BorderRadius.circular(12),
9 ),
10 ),
11 child: Text('Styled Button'),
12)
13
14// Button with icon
15ElevatedButton.icon(
16 onPressed: () {},
17 icon: Icon(Icons.download),
18 label: Text('Download'),
19)

Disabled Button

💡 Disabled Button

Set `onPressed: null` to disable a button.

GestureDetector

GestureDetector lets you make any widget respond to taps, swipes, and other touch gestures. This is useful when you need custom interactive elements that are not standard buttons.

dart
1GestureDetector(
2 onTap: () => print('Tapped!'),
3 onDoubleTap: () => print('Double tap!'),
4 onLongPress: () => print('Long press!'),
5 child: Container(
6 padding: EdgeInsets.all(20),
7 color: Colors.blue,
8 child: Text('Tap me'),
9 ),
10)
11
12// InkWell - same but with ripple effect
13InkWell(
14 onTap: () {},
15 borderRadius: BorderRadius.circular(12),
16 child: Container(
17 padding: EdgeInsets.all(20),
18 child: Text('Tap me'),
19 ),
20)

Action Hierarchy For Better UX

Not all actions should look equally important:

  • Primary action: ElevatedButton
  • Secondary action: OutlinedButton
  • Tertiary action: TextButton

When hierarchy is clear, users make faster decisions and commit fewer mistakes.

Interaction Quality Checklist

  • Primary action is visually dominant but not overwhelming.
  • Disabled state is meaningful and communicates why unavailable.
  • Tap areas are large enough for mobile comfort.
  • Rapid repeat taps are handled safely in async actions.

This Lesson In Simple Words

Interactive widgets for user input. Widgets are reusable UI blocks. You combine them like LEGO pieces to build screens.

Your level focus

Build confidence with basics first; speed comes later.

One practical habit

Sketch the widget tree first, then code from top to bottom.

Deep Understanding Guide

Why this lesson matters

Most Flutter productivity comes from understanding layout rules and composing widgets cleanly.

Study flow for better retention

  1. Read one section, run one tiny example, then explain the idea in your own words.
  2. When a UI bug appears, inspect constraints and parent-child relations before changing random values.
  3. If you can teach it in 45 seconds without notes, you understood it.

Common Mistakes To Avoid

  • Nesting too many widgets without extracting reusable pieces.
  • Ignoring constraints and guessing with random SizedBox heights.
  • Using one giant build method for unrelated UI sections.
  • Putting heavy calculations directly in build methods.

Practice Sprint (15-25 Minutes)

  • Before running sample code, predict output and behavior in one sentence.
  • Build one card layout with Row/Column and rebuild it using Stack for comparison.
  • Split a large widget into 3 smaller widgets with clear responsibilities.
  • Use const constructors where possible and observe rebuild behavior.
  • Complete the required exercises without using hints on the first attempt.
  • Answer this question out loud before checking quiz options: "Which button type has a filled background?".

Quick Glossary

  • widget: A reusable UI building block in Flutter.

Code Comprehension Drill

  • State the purpose of the code block in one line before reading details.
  • Mark inputs, state changes, and final output.
  • Change one small value and predict what should happen before running.
  • Run again and compare your prediction with actual behavior.

Lesson Completion Checklist

  • I can explain "Buttons & Input" in simple words without reading notes.
  • I can describe one real app situation where this concept is required.
  • I know at least one mistake to avoid: Nesting too many widgets without extracting reusable pieces.
  • I can modify one code sample and correctly predict the behavior change.
  • I can finish required exercises with understanding, not trial-and-error guesses.

Frequently Asked Questions

Which button type has a filled background?

ElevatedButton has a filled background, making it stand out.

How do you disable a button?

Setting onPressed to null makes the button disabled and greyed out.

InkWell differs from GestureDetector by:

InkWell shows Material ripple animation on tap.

How do you add an icon to an ElevatedButton?

ElevatedButton.icon() constructor creates a button with both an icon and label.

Suggest Improvement

Something seems incorrect, unclear, or missing? Let us know.

About The Author

FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.

Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.

Sign in to continue with exercises and quiz for this lesson.

Sign In to Continue