What is the purpose of the Image.asset widget in Flutter?
It displays an image stored locally in the app's assets folder. You must declare the image path in pubspec.yaml to use it.
Click to reveal answer
beginner
How do you display an image from the internet in Flutter?
Use the Image.network widget and provide the image URL as a string.
Click to reveal answer
intermediate
Why should you add a placeholder or error widget when using Image.network?
Because network images may take time to load or fail. Placeholders improve user experience by showing a temporary image or message.
Click to reveal answer
intermediate
What is the role of the fit property in the Image widget?
It controls how the image fits inside its container, for example, BoxFit.cover fills the container while keeping aspect ratio.
Click to reveal answer
beginner
How do you declare an image asset in Flutter's pubspec.yaml file?
Under the flutter: section, add assets: and list the image file path(s) relative to the project root.
Click to reveal answer
Which widget is used to display a local image asset in Flutter?
AImage.asset
BImage.network
CImage.file
DImage.memory
✗ Incorrect
Image.asset is for local assets. Image.network is for internet images.
What must you do before using an image asset in Flutter?
ANothing special
BUpload it to a server
CDeclare it in <code>pubspec.yaml</code>
DConvert it to base64
✗ Incorrect
You must declare image assets in pubspec.yaml so Flutter includes them in the app bundle.
Which property controls how an image fits inside its container?
Aalignment
Bfit
Cscale
Drepeat
✗ Incorrect
The fit property defines how the image scales and fits inside its box.
What happens if a network image fails to load in Flutter?
AAn error widget can be shown if provided
BNothing is shown by default
CThe app crashes
DThe image asset is shown instead
✗ Incorrect
You can provide an error widget to show if the network image fails to load.
Which widget would you use to show an image from a URL?
AImage.memory
BImage.asset
CImage.file
DImage.network
✗ Incorrect
Image.network loads images from the internet using a URL.
Explain how to display a local image asset in a Flutter app from start to finish.
Think about where the image lives and how Flutter knows about it.
You got /3 concepts.
Describe how to handle loading and error states when showing a network image in Flutter.
Consider user experience when internet is slow or unavailable.
You got /3 concepts.
Practice
(1/5)
1. Which Flutter widget is used to display an image stored locally inside your app's assets folder?
easy
A. Image.asset
B. Image.network
C. Image.file
D. Image.memory
Solution
Step 1: Understand image sources in Flutter
Flutter provides different constructors for Image widget depending on the source: asset, network, file, or memory.
Step 2: Identify the correct constructor for local assets
Images bundled with the app are accessed using Image.asset.
Final Answer:
Image.asset -> Option A
Quick Check:
Local image = Image.asset [OK]
Hint: Local images use Image.asset constructor [OK]
Common Mistakes:
Using Image.network for local files
Confusing Image.file with assets
Not adding assets to pubspec.yaml
2. Which of the following is the correct syntax to load an image from the internet in Flutter?
easy
A. Image.asset('https://example.com/image.png')
B. Image.network('https://example.com/image.png')
C. Image.file('https://example.com/image.png')
D. Image.memory('https://example.com/image.png')
Solution
Step 1: Identify the correct constructor for network images
To load images from the internet, Flutter uses Image.network with the URL as a string parameter.
Step 2: Check syntax correctness
The syntax Image.network('https://example.com/image.png') is correct and will load the image from the URL.
Final Answer:
Image.network('https://example.com/image.png') -> Option B
Quick Check:
Network image = Image.network [OK]
Hint: Use Image.network for URLs [OK]
Common Mistakes:
Using Image.asset for URLs
Passing URL to Image.file
Missing quotes around URL string
3. What will be displayed when this Flutter code runs?
Image.asset('images/logo.png')
Assuming the image file exists and is declared in pubspec.yaml.
medium
A. An error because 'images/logo.png' is a network URL
B. A blank space because Image.asset cannot load images
C. The image 'logo.png' from the assets folder is shown
D. A loading spinner while the image downloads
Solution
Step 1: Confirm asset image usage
The code uses Image.asset with a relative path 'images/logo.png', which means it loads a local asset image.
Step 2: Check conditions for display
Since the image exists and is declared in pubspec.yaml, Flutter will display the image correctly.
Final Answer:
The image 'logo.png' from the assets folder is shown -> Option C
Quick Check:
Image.asset with valid asset = image shown [OK]
Hint: Image.asset shows local images if declared properly [OK]
Common Mistakes:
Confusing asset path with network URL
Not declaring asset in pubspec.yaml
Expecting loading spinner for local images
4. Identify the error in this Flutter code snippet:
Image.asset('https://example.com/image.png')
medium
A. Using Image.asset with a network URL causes an error
B. Missing semicolon at the end
C. Image.asset requires a File object, not a string
D. The URL string is missing quotes
Solution
Step 1: Understand Image.asset usage
Image.asset is for local asset files, not URLs.
Step 2: Identify misuse of URL with Image.asset
Passing a network URL string to Image.asset causes a runtime error because it expects a local asset path.
Final Answer:
Using Image.asset with a network URL causes an error -> Option A
Quick Check:
Image.asset + URL = error [OK]
Hint: Image.asset only accepts local paths, not URLs [OK]
Common Mistakes:
Thinking Image.asset works with URLs
Ignoring asset declaration in pubspec.yaml
Confusing Image.file with Image.asset
5. You want to display a local image named 'icon.png' stored in 'assets/icons/' folder and also show a fallback network image if the local image fails to load. Which Flutter code snippet correctly implements this?
hard
A. Image.file('assets/icons/icon.png', onError: () => Image.network('https://example.com/fallback.png'))
B. Image.network('assets/icons/icon.png', fallback: Image.asset('https://example.com/fallback.png'))
C. Image.asset('assets/icons/icon.png', fallbackImage: Image.network('https://example.com/fallback.png'))
D. Image.asset('assets/icons/icon.png', errorBuilder: (context, error, stackTrace) => Image.network('https://example.com/fallback.png'))
Solution
Step 1: Understand fallback handling in Image.asset
Flutter's Image.asset supports an errorBuilder callback to handle loading errors and show alternative widgets.
Step 2: Check which option uses errorBuilder correctly
Image.asset('assets/icons/icon.png', errorBuilder: (context, error, stackTrace) => Image.network('https://example.com/fallback.png')) uses errorBuilder to show a network image if the asset fails, which is the correct approach.
Final Answer:
Image.asset with errorBuilder showing Image.network fallback -> Option D
Quick Check:
Use errorBuilder for fallback images [OK]
Hint: Use errorBuilder in Image.asset for fallback images [OK]
Common Mistakes:
Using fallback or onError props that don't exist
Passing URLs to Image.asset directly
Confusing Image.file with asset images
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.