What is the purpose of the Text widget in Flutter?
The Text widget displays a string of text with single style in the app's UI. It is used to show readable content to users.
Click to reveal answer
beginner
How do you change the color of text in a Text widget?
You change the text color by using the style property with a TextStyle object, setting its color property, e.g., Text('Hello', style: TextStyle(color: Colors.red)).
Click to reveal answer
beginner
What property of TextStyle controls the font size?
The fontSize property controls the size of the text font, for example: TextStyle(fontSize: 20) makes the text larger.
Click to reveal answer
beginner
How can you make text bold using the Text widget?
Use the fontWeight property inside TextStyle and set it to FontWeight.bold, like Text('Bold', style: TextStyle(fontWeight: FontWeight.bold)).
Click to reveal answer
beginner
What does the textAlign property do in a Text widget?
The textAlign property controls how the text is aligned horizontally within its container, such as TextAlign.left, TextAlign.center, or TextAlign.right.
Click to reveal answer
Which property is used to change the font size of a Text widget?
Acolor
BfontWeight
CtextAlign
DfontSize
✗ Incorrect
The fontSize property inside TextStyle sets the size of the text.
How do you make text italic in Flutter?
Astyle: TextStyle(fontStyle: FontStyle.italic)
Bstyle: TextStyle(fontWeight: FontWeight.italic)
CtextAlign: TextAlign.italic
Dcolor: Colors.italic
✗ Incorrect
Use fontStyle: FontStyle.italic inside TextStyle to make text italic.
What does the textAlign property affect?
AFont size
BHorizontal alignment of text
CText color
DText decoration
✗ Incorrect
textAlign controls how text is aligned horizontally inside its container.
Which widget is used to display text in Flutter?
AText
BContainer
CRow
DColumn
✗ Incorrect
The Text widget displays text on the screen.
How do you change the color of text to blue?
Acolor: Colors.blue
BtextColor: Colors.blue
Cstyle: TextStyle(color: Colors.blue)
DfontColor: Colors.blue
✗ Incorrect
You set the color inside TextStyle using the color property.
Explain how to style text in Flutter using the Text widget and TextStyle.
Think about how you change color, size, weight, and alignment.
You got /7 concepts.
Describe the role of the textAlign property and give examples of its values.
Consider how text looks inside a box when aligned differently.
You got /5 concepts.
Practice
(1/5)
1. What does the Text widget do in Flutter?
easy
A. Manages app navigation between screens
B. Creates buttons for user interaction
C. Draws shapes like circles and rectangles
D. Displays words or sentences on the screen
Solution
Step 1: Understand the purpose of the Text widget
The Text widget is designed to show text content on the screen in Flutter apps.
Step 2: Compare with other widget functions
Buttons handle taps, shapes draw graphics, and navigation manages screens, which are not the Text widget's job.
Final Answer:
Displays words or sentences on the screen -> Option D
Quick Check:
Text widget = display text [OK]
Hint: Text widget always shows text on screen [OK]
Common Mistakes:
Confusing Text with Button widget
Thinking Text draws shapes
Mixing Text with navigation widgets
2. Which of these is the correct way to set the text color to red in a Text widget?
easy
A. Text('Hello', style: TextColor(red))
B. Text('Hello', style: TextStyle(color: Colors.red))
C. Text('Hello', color: Colors.red)
D. Text('Hello', style: ColorText(Colors.red))
Solution
Step 1: Recall how to style text color in Flutter
Text color is set inside the style property using TextStyle with the color parameter.
Step 2: Check each option's syntax
Text('Hello', style: TextStyle(color: Colors.red)) uses TextStyle(color: Colors.red) correctly; others use invalid or nonexistent syntax.
Final Answer:
Text('Hello', style: TextStyle(color: Colors.red)) -> Option B
Quick Check:
Text color set via style: TextStyle(color: ...) [OK]
Hint: Use style: TextStyle(color: ...) to set text color [OK]
Common Mistakes:
Trying to set color directly on Text widget
Using wrong class names like TextColor
Missing the style property
3. What will be the visible output of this Flutter code?
fontSize expects a number (double), but '20' is a string, causing a type error.
Step 2: Validate other syntax parts
Text widget supports style, commas are correct, and TextStyle is valid inside Text.
Final Answer:
fontSize should be a double, not a string -> Option A
Quick Check:
fontSize type error = fontSize should be a double, not a string [OK]
Hint: fontSize must be a number, not quoted text [OK]
Common Mistakes:
Putting fontSize in quotes
Thinking style is invalid in Text
Missing commas causing syntax errors
5. You want to display a long text that might not fit in one line and should show an ellipsis (...) at the end if it overflows. Which Text widget code correctly achieves this?
hard
A. Text('Long text here', overflow: TextOverflow.ellipsis, maxLines: 1)
B. Text('Long text here', maxLines: 1, overflow: TextOverflow.clip)
C. Text('Long text here', overflow: TextOverflow.fade, maxLines: 2)
D. Text('Long text here', maxLines: null, overflow: TextOverflow.ellipsis)
Solution
Step 1: Understand overflow and maxLines usage
To show ellipsis when text is too long, overflow must be TextOverflow.ellipsis and maxLines set to 1 to limit lines.
Step 2: Evaluate each option
Text('Long text here', overflow: TextOverflow.ellipsis, maxLines: 1) correctly uses overflow: TextOverflow.ellipsis and maxLines: 1. Others either use wrong overflow or maxLines values.
Final Answer:
Text('Long text here', overflow: TextOverflow.ellipsis, maxLines: 1) -> Option A