Learn/Core Widgets/Images & Icons

Images & Icons

Display images and icons in your app

4 min~5 min read+25 FX

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

Table of Contents

  1. 1. BoxFit Options
  2. 2. Adding Assets
  3. 3. Image Quality and Performance Basics
  4. 4. This Lesson In Simple Words
  5. 5. Your level focus
  6. 6. One practical habit
  7. 7. Deep Understanding Guide
  8. 8. Why this lesson matters
  9. 9. Study flow for better retention
  10. 10. 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

Image Widget

The Image widget displays images from various sources, including the internet, local assets, and memory. It is one of the most frequently used widgets in any Flutter app.

dart
1// From internet
2Image.network(
3 'https://example.com/image.jpg',
4 width: 200,
5 height: 200,
6 fit: BoxFit.cover,
7 loadingBuilder: (context, child, progress) {
8 if (progress == null) return child;
9 return CircularProgressIndicator();
10 },
11 errorBuilder: (context, error, stackTrace) {
12 return Icon(Icons.error);
13 },
14)
15
16// From assets (local files)
17Image.asset(
18 'assets/images/logo.png',
19 width: 100,
20)
21
22// From memory
23Image.memory(bytes)

BoxFit Options

The BoxFit property controls how an image is resized to fit inside its container. Choosing the right fit prevents images from looking stretched or leaving unwanted gaps.

dart
1Image.network(
2 url,
3 fit: BoxFit.cover, // Fills container, may crop
4 // Other options:
5 // BoxFit.contain - Show entire image, may have gaps
6 // BoxFit.fill - Stretch to fill, distorts
7 // BoxFit.fitWidth - Match width, may crop height
8 // BoxFit.fitHeight - Match height, may crop width
9 // BoxFit.none - No resizing
10)

Adding Assets

  1. Create assets/images/ folder
  2. Add to pubspec.yaml:
flutter:
  assets:
    - assets/images/
  1. Use Image.asset('assets/images/photo.png')

Icons

Flutter comes with a comprehensive set of Material Icons built right in. You can use them without installing any additional packages.

dart
1// Basic icon
2Icon(Icons.home)
3
4// Styled icon
5Icon(
6 Icons.favorite,
7 color: Colors.red,
8 size: 32,
9)
10
11// With background
12Container(
13 padding: EdgeInsets.all(12),
14 decoration: BoxDecoration(
15 color: Colors.blue.withValues(alpha: 0.1),
16 borderRadius: BorderRadius.circular(12),
17 ),
18 child: Icon(Icons.settings, color: Colors.blue),
19)

Find Icons

💡 Find Icons

Browse all Material Icons at fonts.google.com/icons. You can also use autocomplete in your editor by typing `Icons.` to see all available icon suggestions.

Image Quality and Performance Basics

For production apps, image handling should balance quality and speed:

  • use suitable image dimensions for target usage
  • avoid loading huge images into tiny containers
  • provide graceful loading and error fallbacks
  • use consistent icon sizes for visual rhythm

Good media handling improves both perceived quality and app responsiveness.

Media Checklist

  • Each network image has loading and error handling.
  • BoxFit choice matches the visual goal (cover vs contain).
  • Asset paths are declared correctly in pubspec.yaml.
  • Icons are semantically meaningful, not decorative clutter.

This Lesson In Simple Words

Display images and icons in your app. This lesson adds one more building block for creating stable and user-friendly Flutter apps.

Your level focus

Build confidence with basics first; speed comes later.

One practical habit

After reading, rewrite the concept in your own words and apply it in a tiny runnable sample.

Deep Understanding Guide

Why this lesson matters

Each lesson becomes useful when you connect concept, implementation, and real-user outcome together.

Study flow for better retention

  1. Read one section, run one tiny example, then explain the idea in your own words.
  2. Use a simple cycle: understand, implement, test, and explain.
  3. If you can teach it in 45 seconds without notes, you understood it.

Common Mistakes To Avoid

  • Moving forward without checking whether the current concept is truly clear.
  • Copying code exactly without experimenting with small changes.
  • Skipping edge cases and only testing happy-path behavior.
  • Assuming one pattern works for every scenario without trade-off analysis.

Practice Sprint (15-25 Minutes)

  • Before running sample code, predict output and behavior in one sentence.
  • Build one tiny example from memory after finishing this lesson.
  • Write one paragraph about where this concept fits in a real app.
  • Create one failure scenario and verify your app handles it safely.
  • Complete the required exercises without using hints on the first attempt.
  • Answer this question out loud before checking quiz options: "How do you load an image from the internet?".

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 "Images & Icons" 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: Moving forward without checking whether the current concept is truly clear.
  • 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

How do you load an image from the internet?

Image.network() loads images from URLs.

BoxFit.cover does what?

cover fills the container completely, cropping the image if needed.

Where do you declare asset images?

Assets are declared in the flutter section of pubspec.yaml.

What does Image.network() errorBuilder do?

errorBuilder provides a widget to display when the network image fails to load.

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