Explore Flutter widgets with this comprehensive collection of MCQs designed for developers and learners. Dive into concepts such as Stateless vs. Stateful widgets, common widgets like Text, Image, and Container, layout principles involving constraints, padding, and margins, and techniques for customizing widgets. Perfect your skills with these Flutter MCQ questions and answers!
Multiple Choice Questions (MCQs)
Stateless vs. Stateful Widgets
What defines a Stateless widget in Flutter? a) It can change dynamically. b) It does not maintain state. c) It has a mutable state. d) It requires user interaction.
Which class is the base for Stateful widgets in Flutter? a) StatelessWidget b) StatefulWidget c) WidgetBase d) StateWidget
In which lifecycle method of a Stateful widget can you initialize data? a) build() b) dispose() c) initState() d) didUpdateWidget()
What happens when setState() is called in a Stateful widget? a) The widget rebuilds completely. b) The widget is destroyed. c) The widget’s state changes permanently. d) No visible change occurs.
Which is true about Stateless widgets? a) They can hold a state across rebuilds. b) They are ideal for dynamic user interfaces. c) They are immutable. d) They must use setState() for updates.
Common Widgets: Text, Image, Container, Row, Column
What is the primary purpose of a Container widget? a) To display text b) To hold and position child widgets c) To show images d) To create forms
Which widget is used to display a simple piece of text? a) TextField b) Label c) Text d) Font
What is the fit property used for in the Image widget? a) To position the image within a widget b) To adjust the widget’s padding c) To define how an image should fill its container d) To manage caching for images
Which widget aligns its children in a horizontal direction? a) Column b) Row c) Stack d) Flex
What happens if no child is provided to a Container widget? a) It throws an error. b) It becomes invisible but still occupies space. c) It collapses. d) It defaults to a Text widget.
Layout Principles: Constraints, Sizes, Padding, and Margins
What does the BoxConstraints class represent in Flutter? a) A set of rules for defining widget size b) Animation properties for widgets c) Color schemes for widgets d) Debugging tools
The padding property of a widget: a) Adds space outside the widget’s border b) Adds space inside the widget’s border c) Centers the widget d) Changes the widget’s size
What happens when a widget’s size exceeds its parent’s constraints? a) It expands without limits. b) The widget throws an error. c) It clips to fit the constraints. d) The layout adjusts dynamically.
Which property controls external spacing around a widget? a) margin b) padding c) constraints d) alignment
What is the default alignment for widgets in a Row? a) Center b) Start c) End d) Stretch
Customizing Widgets
What method is typically used to customize a widget’s appearance? a) setStyle() b) applyChanges() c) modify() d) Decoration property
Which property allows you to set a background color for a Container? a) color b) backgroundColor c) decoration d) shade
How do you add rounded corners to a Container? a) Using borderRadius in BoxDecoration b) Setting the clipShape property c) Modifying the cornerRadius attribute d) Adding a curve widget
Which widget is used to apply gradients to another widget? a) ShaderMask b) ColorFilter c) Container d) GradientBox
How can you add a shadow effect to a widget? a) Using the elevation property b) Applying a BoxShadow to BoxDecoration c) Adding the shadowEffect property d) Wrapping the widget in a Shadow widget
Additional Concepts
What is the primary difference between Padding and Margin? a) Padding adjusts external space; margin adjusts internal space. b) Padding adjusts internal space; margin adjusts external space. c) Both do the same function. d) Padding is mandatory, margin is optional.
Which property in a Text widget adjusts text alignment? a) align b) textAlign c) justify d) direction
To make a widget respond to a tap event, which widget should be used? a) GestureDetector b) Container c) Stack d) Row
Which layout widget is ideal for overlaying widgets? a) Row b) Stack c) Flex d) Grid
What does the Expanded widget do in a Row or Column? a) Forces the widget to center-align b) Adds scrollability c) Divides available space among widgets d) Makes the widget invisible
Answer Table
Qno
Answer
1
b) It does not maintain state.
2
b) StatefulWidget
3
c) initState()
4
a) The widget rebuilds completely.
5
c) They are immutable.
6
b) To hold and position child widgets
7
c) Text
8
c) To define how an image should fill its container
9
b) Row
10
b) It becomes invisible but still occupies space.
11
a) A set of rules for defining widget size
12
b) Adds space inside the widget’s border
13
c) It clips to fit the constraints.
14
a) margin
15
b) Start
16
d) Decoration property
17
a) color
18
a) Using borderRadius in BoxDecoration
19
a) ShaderMask
20
b) Applying a BoxShadow to BoxDecoration
21
b) Padding adjusts internal space; margin adjusts external space.