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 viaTextStyle, 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
Textwidget andTextStyle.
-
Implement modern Material buttons (
ElevatedButton,TextButton).
-
Render vector graphics using the
Iconwidget.
-
Display images from the internet using
Image.network.
-
Display local project images using
Image.asset.
3. Text and Typography
TheText widget displays a string. To change its appearance, you pass a TextStyle object into the style: property.
dart
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
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
6. Images (Network and Asset)
Apps are highly visual. Flutter provides theImage widget to render graphics.
1. Web Images (Network): Instantly load an image from a URL.
dart
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
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-inCircleAvatar widget.
dart
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
onPressedproperty tonull.
onPressed: null, // Button is now disabled!
10. Common Mistakes
-
Forgetting
Image.networkrequires Internet: If your Android emulator does not have internet access configured properly,Image.networkwill 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.
Create a
Row. Add padding to it.
-
2.
The first child is a
CircleAvatardisplaying a profile picture (NetworkImage).
-
3.
Add a
SizedBox(width: 10)for spacing.
-
4.
Add a
Columncontaining twoTextwidgets: "username" (bold) and "Sponsored" (grey, small). Set the Column'scrossAxisAlignmentto Start.
-
5.
Wrap that
Columnin anExpandedwidget to push the next item to the far right.
-
6.
The final child is an
IconButtondisplayingIcons.more_vert(the three dots menu).
- 7. You have just built a production-ready social media UI header!
12. Practice Exercises
-
1.
Write the code to create an
ElevatedButtonthat prints "Login" to the console when clicked.
-
2.
What property of the
Textwidget 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, anOutlinedButton, and aTextButtonin Flutter's Material Design system.
-
Q: Contrast
Image.assetwithImage.network. Explain the setup required in the project architecture forImage.assetto 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 usingTextStyle, 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.