[{"id":"flutterintermediate-001","courseId":"flutter-intermediate","domain":"widgets-layout","topic":"Keys decide which element is reused","prompt":"A Column holds two unkeyed StatefulWidgets of the same class. A setState swaps their order in the list. What happens to the two State objects?","hint":"Think about what the framework uses to pair a new widget with an existing element when no key is given.","explain":"A key is an identifier that lets a new widget claim an existing element. Without one, the framework needs a fallback rule to pick which element a new widget reuses, and that rule can attach state to the wrong widget.","source":"https://api.flutter.dev/flutter/foundation/Key-class.html","interaction":{"type":"single"},"options":[{"id":"a","text":"Each State follows its own widget to the other slot.","whyNot":"A State follows its widget only when a matching key is given; without one, matching falls back to other facts about the widget."},{"id":"b","text":"Flutter rejects the swap, because unkeyed siblings can't change order.","whyNot":"Unkeyed siblings are not rejected; the framework simply reuses elements by type and position."},{"id":"c","text":"Each State stays in its slot and is handed to whichever widget now occupies it.","why":"Unkeyed widgets are matched by runtimeType and position, so the existing State stays where it was."},{"id":"d","text":"Both States are disposed and new ones are created.","whyNot":"Matching by runtimeType and position reuses the existing elements, so the States are kept rather than recreated."}],"answer":"c","explanation":"Keys let a widget claim an existing element across rebuilds. Unkeyed widgets are matched by runtimeType and position, so a State can end up attached to a different widget.","concept":"Keys let a widget claim an existing element across rebuilds. Unkeyed widgets are matched by runtimeType and position, so a State can end up attached to a different widget.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Without keys on reordered stateful siblings, state stays in its slot and can show the wrong data."]},{"id":"flutterintermediate-002","courseId":"flutter-intermediate","domain":"widgets-layout","topic":"Widget, element and render trees","prompt":"Widgets are the objects Flutter lays out and composites, so the widget tree is the only tree that matters for layout.","hint":"Consider whether a widget is a description or the object that sizes itself.","explain":"A UI framework can keep a screen's description separate from the objects that size and paint it. Consider which kind of object does the sizing, and whether descriptions are cheap to create.","source":"https://docs.flutter.dev/resources/architectural-overview","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The page says widgets are immutable configuration that drive separate object trees for layout and compositing."},{"id":"b","text":"False","why":"Widgets configure a tree of objects, and separate object trees handle layout and compositing, so the widget tree is not the only one."}],"answer":"b","explanation":"Widgets are immutable configuration. They are used to manage separate trees of objects for layout and for compositing.","concept":"Widgets are immutable configuration. They are used to manage separate trees of objects for layout and for compositing.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Widgets are cheap descriptions; the render objects below them do the sizing and painting."]},{"id":"flutterintermediate-003","courseId":"flutter-intermediate","domain":"widgets-layout","topic":"LayoutBuilder reads parent constraints","prompt":"A card should switch to a two-column grid only when there is enough width. Which widget calls its builder during layout and passes the parent's constraints?","hint":"Look for the builder that runs while sizes are being decided, not while the tree is built.","explain":"Some builder callbacks run while the tree is being constructed and only receive a context. Others run later, during layout, and receive the limits a parent places on its child.","source":"https://api.flutter.dev/flutter/widgets/LayoutBuilder-class.html","interaction":{"type":"single"},"options":[{"id":"a","text":"Builder","whyNot":"Builder calls its builder function at build time, so it has no layout constraints to pass."},{"id":"b","text":"StatefulBuilder","whyNot":"StatefulBuilder passes its builder a setState callback, not the parent's constraints."},{"id":"c","text":"LayoutBuilder","why":"It calls its builder at layout time and provides the parent widget's constraints."},{"id":"d","text":"MediaQuery.sizeOf(context)","whyNot":"It returns the size of the whole view, not the constraints a parent passes to a child."}],"answer":"c","explanation":"LayoutBuilder calls its builder during layout and provides the parent's constraints, unlike Builder, which calls its builder at build time.","concept":"LayoutBuilder calls its builder during layout and provides the parent's constraints, unlike Builder, which calls its builder at build time.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["LayoutBuilder's builder gets the parent's constraints at layout time, so it can choose a layout by the space available."]},{"id":"flutterintermediate-004","courseId":"flutter-intermediate","domain":"widgets-layout","topic":"MediaQuery data for screen size","prompt":"A header needs only the screen size. It should rebuild when that size changes, but not when other media data changes. Which call should it make?","hint":"Consider how much of the media data this widget actually depends on.","explain":"A widget that reads inherited data is rebuilt whenever the part of that data it depends on changes. Narrower reads depend on less, so they rebuild less often.","source":"https://api.flutter.dev/flutter/widgets/MediaQuery-class.html","interaction":{"type":"single"},"options":[{"id":"a","text":"MediaQuery.of(context).size","whyNot":"MediaQuery.of rebuilds the widget whenever any field of the data changes, not only the size."},{"id":"b","text":"MediaQuery.sizeOf(context)","why":"sizeOf rebuilds the widget only when the size changes, which is the narrow dependency this header needs."},{"id":"c","text":"MediaQuery.maybeOf(context)","whyNot":"maybeOf returns null instead of throwing when no MediaQuery is in scope; that concerns a missing scope, not the size."},{"id":"d","text":"LayoutBuilder","whyNot":"It gives the constraints the parent passes, which may be smaller than the whole screen."}],"answer":"b","explanation":"MediaQuery.sizeOf rebuilds a widget only when the size changes; MediaQuery.of rebuilds it when any MediaQueryData field changes.","concept":"MediaQuery.sizeOf rebuilds a widget only when the size changes; MediaQuery.of rebuilds it when any MediaQueryData field changes.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Prefer the specific MediaQuery accessors such as sizeOf; MediaQuery.of rebuilds on any change."]},{"id":"flutterintermediate-005","courseId":"flutter-intermediate","domain":"widgets-layout","topic":"Stack and Positioned children","prompt":"A Stack holds a Positioned child and a plain child, and the list is [A, B, C]. Which TWO statements about this Stack are correct?","hint":"Think about what sets the stack's size and what decides which child ends up on top.","explain":"A layering container has to decide two things: how big it is, and which child is drawn over which. Consider which children can influence each decision, and what it means for a child to be drawn later.","source":"https://api.flutter.dev/flutter/widgets/Stack-class.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The stack sizes itself to fit its non-positioned children.","why":"The page says the stack sizes itself to contain all the non-positioned children."},{"id":"b","text":"The first child in the list paints at the bottom.","why":"Children paint in order, so the first child is at the bottom and later children paint over it."},{"id":"c","text":"Positioned children decide the size of the stack.","whyNot":"Positioned children are placed relative to the stack; the stack's size comes from its non-positioned children."},{"id":"d","text":"The last child in the list paints at the bottom.","whyNot":"The last child is painted last, so it lands on top rather than at the bottom."},{"id":"e","text":"Positioned children can be placed relative to their own size.","whyNot":"A Stack can't position children relative to their size or the stack's own size; that needs a different layout widget."},{"id":"f","text":"Every child needs a non-null key before the Stack paints it.","whyNot":"Keys are only suggested when reordering children, to move their underlying objects; they are not needed to paint."}],"answer":"ab","explanation":"A Stack sizes itself to its non-positioned children and paints its children in order, so the first child is at the bottom.","concept":"A Stack sizes itself to its non-positioned children and paints its children in order, so the first child is at the bottom.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Stack paints in list order, so the child that should appear on top goes later in the list."]}]