Skip to main content
Flutter Basics – Complete Beginner to Advanced Guide
CHAPTER 09 Beginner

Flutter Text, Buttons, Icons, and Images

Updated: May 16, 2026
25 min read

# CHAPTER 9

Flutter Text, Buttons, Icons, and Images

1. Introduction

A beautifully structured layout is meaningless if the content inside it is boring. To build an engaging app, you need sharp typography, clear interactive buttons, recognizable icons, and high-resolution imagery. In this chapter, we will master the core visual elements: Text, Buttons, Icons, and Images. We will learn how to apply fonts and colors via TextStyle, explore the modern Material 3 button suite (ElevatedButton, TextButton, IconButton), utilize Flutter's massive built-in icon library, and fetch images from both the local hard drive and the internet.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Style typography using the Text widget and TextStyle.
  • Implement modern Material buttons (ElevatedButton, TextButton).
  • Render vector graphics using the Icon widget.
  • Display images from the internet using Image.network.
  • Display local project images using Image.asset.

3. Text and Typography

The Text widget displays a string. To change its appearance, you pass a TextStyle object into the style: property.
dart
1234567891011
Text(
  "Welcome to Flutter!",
  style: TextStyle(
    fontSize: 24.0,           // Size of the font
    fontWeight: FontWeight.bold, // Make it bold
    color: Colors.blueAccent,    // Change color
    letterSpacing: 2.0,       // Space between characters
    fontStyle: FontStyle.italic,
  ),
  textAlign: TextAlign.center, // Center the text block
)

4. The Material Button Suite

Flutter uses Material Design buttons. They automatically handle ripple click animations and shadows.
  • ElevatedButton: A raised button with a background color and drop shadow. Primary call-to-action (e.g., "Submit").
  • TextButton: A flat, transparent button. Secondary action (e.g., "Cancel" or "Forgot Password").
  • OutlinedButton: A transparent button with a colored border.
dart
1234567891011
ElevatedButton(
  onPressed: () {
    print("Button Clicked!"); // Runs when tapped
  },
  style: ElevatedButton.styleFrom(
    backgroundColor: Colors.green, // Background color
    foregroundColor: Colors.white, // Text color
    elevation: 5, // Shadow depth
  ),
  child: Text("Submit Form"),
)

5. Icons and IconButtons

Flutter includes thousands of free Google Material Icons built directly into the SDK. You do not need to download image files for icons!
  • Icon(Icons.home, color: Colors.blue, size: 30): Displays a static home icon.
  • IconButton: Turns an icon into a clickable button with a circular ripple effect.
dart
12345678
IconButton(
  icon: Icon(Icons.favorite),
  color: Colors.red,
  iconSize: 40,
  onPressed: () {
    print("Heart Clicked!");
  },
)

6. Images (Network and Asset)

Apps are highly visual. Flutter provides the Image widget to render graphics. 1. Web Images (Network): Instantly load an image from a URL.
dart
123456
Image.network(
  'https://example.com/cute_dog.jpg',
  width: 200,
  height: 200,
  fit: BoxFit.cover, // Crops the image to perfectly fill the 200x200 box!
)

2. Local Images (Asset): As discussed in Chapter 4, if you put an image in your assets/ folder and register it in pubspec.yaml, you can load it offline:

dart
1
Image.asset('assets/images/logo.png', width: 100)

7. Circular Images (Avatars)

A very common UI pattern is a circular profile picture. Do not manually crop your images into circles! Use the built-in CircleAvatar widget.
dart
1234
CircleAvatar(
  radius: 50, // Size of the circle
  backgroundImage: NetworkImage('https://example.com/profile.jpg'),
)

8. Visual Learning: BoxFit Properties

When an image doesn't perfectly match the dimensions of its container, BoxFit dictates how it reacts:
  • BoxFit.contain: Scales the image so the entire thing is visible (leaves empty borders).
  • BoxFit.cover: Zooms in and crops the image so there is no empty space. (Used 90% of the time for modern UI).
  • BoxFit.fill: Stretches and distorts the image to fit the box. (Rarely used).

9. Best Practices

  • Null Safety in Buttons: If you want to disable a button (make it greyed out and unclickable), set the onPressed property to null.
onPressed: null, // Button is now disabled!

10. Common Mistakes

  • Forgetting Image.network requires Internet: If your Android emulator does not have internet access configured properly, Image.network will silently fail and show a blank space or throw a network error in the console.

11. Mini Project: Build an Instagram Post Header

Objective: Combine Text, Icons, Images, and Layouts into a real-world component.
  1. 1. Create a Row. Add padding to it.
  1. 2. The first child is a CircleAvatar displaying a profile picture (NetworkImage).
  1. 3. Add a SizedBox(width: 10) for spacing.
  1. 4. Add a Column containing two Text widgets: "username" (bold) and "Sponsored" (grey, small). Set the Column's crossAxisAlignment to Start.
  1. 5. Wrap that Column in an Expanded widget to push the next item to the far right.
  1. 6. The final child is an IconButton displaying Icons.more_vert (the three dots menu).
  1. 7. You have just built a production-ready social media UI header!

12. Practice Exercises

  1. 1. Write the code to create an ElevatedButton that prints "Login" to the console when clicked.
  1. 2. What property of the Text widget do you modify to center-align a paragraph of text?

13. MCQs with Answers

Question 1

To ensure an image perfectly fills a 200x200 pixel box without distorting or stretching the image's aspect ratio (cropping the overflow instead), which BoxFit property should be used?

Question 2

You want to place a clickable "Trash Can" icon next to an item in a shopping cart list. Which widget is specifically designed to make an icon clickable while providing proper Material ripple animations?

14. Interview Questions

  • Q: Explain the visual and semantic differences between an ElevatedButton, an OutlinedButton, and a TextButton in Flutter's Material Design system.
  • Q: Contrast Image.asset with Image.network. Explain the setup required in the project architecture for Image.asset to function correctly.
  • Q: A developer wants to temporarily disable a "Submit" button until a form is fully filled out. How is a button disabled in Flutter without creating a custom UI overlay?

15. FAQs

Q: Can I use custom fonts downloaded from the internet? A: Yes! You download the .ttf font file, put it in an assets/fonts folder, register the font family in pubspec.yaml, and then specify fontFamily: 'MyFont' inside your TextStyle!

16. Summary

In Chapter 9, we filled our wireframe layouts with beautiful, interactive content. We learned to style typography using TextStyle, manipulating weights, sizes, and colors. We implemented primary and secondary actions using the Material button suite (ElevatedButton, TextButton, IconButton). Finally, we brought our UI to life by rendering free Material vector graphics using the Icon widget, and fetching rich imagery from both local assets and the web.

17. Next Chapter Recommendation

Our single-screen app looks gorgeous, but a real app has many screens. How do we move between them? Proceed to Chapter 10: Navigation and Routing in Flutter.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·