Which widget overlays and centers a loading indicator on an image?

Stack overlays and centering non-positioned children.
Stack with Image first (bottom), then Center-wrapped indicator; constrain Stack to image.
Column/Row or manual Positioned offsets instead of Stack/Center alignment.
What's really being asked
This question evaluates whether you understand Flutter's overlay layout model, specifically the Stack widget and the distinction between positioned and non-positioned children. The interviewer wants to see that you know Stack is designed for overlapping widgets, that child order determines z-order with the first child at the bottom, and that centering can be achieved either through Stack-level alignment or by wrapping a child in a Center widget. They also care whether you recognize sizing constraints, because a Stack sizes itself to contain all non-positioned children according to the provided fit and alignment.
The full answer
First, declare Stack as the correct widget because it positions children relative to the edges of its box and supports overlapping in a single layer. Second, state that the Image should be the first child in the children list so it paints at the bottom, with the loading indicator layered above it. Third, explain centering via two valid paths: either set the Stack's alignment property to Alignment.center so all non-positioned children are centered together, or leave the Stack alignment at its default and wrap the loading indicator in a Center widget. Fourth, mention sizing behavior: the Stack will size itself to contain the non-positioned children, so if the image is unconstrained you may need to wrap the Stack in a SizedBox or let the image's own dimensions define the bounds. Fifth, note that the indicator should remain non-positioned; avoid wrapping it in Positioned unless you have a specific offset requirement, since Center or Stack alignment handles centering more robustly.
The mistakes people make
Suggesting Column or Row with mainAxisAlignment and crossAxisAlignment does not overlay widgets; it arranges them sequentially. Proposing absolute Positioned values such as left and top calculated manually to approximate centering is fragile and ignores right-to-left layouts. Using a Scaffold body with centered content does not bind the indicator to the image bounds, so the loader will not track the image if the surrounding layout changes. Forgetting that the first child is at the bottom and placing the image last would hide it behind the indicator. Some candidates also suggest Align without clarifying when Center is preferable.
What usually comes next
How would you add a semi-transparent dark backdrop behind the indicator but over the image? What happens if the image is inside a scrollable list and the loader needs to track it? How would you center a child relative to the Stack's size if the child itself has no intrinsic dimensions? When would you use Positioned.fill instead of Center? How does text direction affect the default top-start alignment?
A concrete example
A concise implementation uses Stack(alignment: Alignment.center, children: [Image.network(url), CircularProgressIndicator()]). Alternatively, keep Stack at its default alignment and write Stack(children: [Image.network(url), Center(child: CircularProgressIndicator())]). In both cases the Stack should be constrained, for instance by placing it inside a SizedBox with fixed width and height or by letting the parent provide tight constraints so the overlay matches the image bounds exactly.
Interview question
In Flutter, which widget structure correctly overlays and centers a loading indicator on top of an image while respecting the image bounds?
- a.A Stack with Alignment.center, placing the loading indicator first and the image second
- b.A Column using mainAxisAlignment to center, placing the indicator after the image
- c.A Stack with the image first and the indicator second as a non-positioned child, centered via Stack alignment or a Center widgetCorrect
- d.A Stack with the image first, wrapping the indicator in Positioned with manually calculated left and top offsets
Why? this is the answer
Stack paints its first child at the bottom, so the image must precede the indicator to remain visible. Centering should rely on Stack alignment or a Center widget for a non-positioned child, whereas manually calculated Positioned offsets are fragile and break in right-to-left layouts.
Just read this? Test yourself on what you have been reading.
Read the original → api.flutter.dev
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on flutter — each one lists the topics its interview covers.
See open roles