Bird
Raised Fist0
Fluttermobile~20 mins

Text widget and styling in Flutter - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Text Styling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
1:30remaining
Text widget color and font size
What will be the color and font size of the text displayed by this Flutter code?
Flutter
Text('Hello Flutter', style: TextStyle(color: Colors.red, fontSize: 24))
AText is black with font size 24
BText is red with default font size
CText is red with font size 24
DText is black with default font size
Attempts:
2 left
💡 Hint
Look at the TextStyle properties inside the Text widget.
📝 Syntax
intermediate
1:30remaining
Correct syntax for bold and italic text
Which option correctly styles the text to be bold and italic in Flutter?
AText('Bold Italic', style: TextStyle(fontWeight: FontWeight.bold, fontStyle: FontStyle.italic))
BText('Bold Italic', style: TextStyle(weight: FontWeight.bold, style: FontStyle.italic))
CText('Bold Italic', style: TextStyle(fontWeight: 'bold', fontStyle: 'italic'))
DText('Bold Italic', style: TextStyle(fontWeight: FontWeight.bold, fontStyle: 'italic'))
Attempts:
2 left
💡 Hint
Check the correct property names and value types for fontWeight and fontStyle.
❓ ui_behavior
advanced
2:00remaining
Text overflow behavior
What happens when this Flutter Text widget is displayed in a narrow container?
Flutter
Container(width: 100, child: Text('This is a very long text that might overflow', overflow: TextOverflow.ellipsis))
AText is cut off with an ellipsis (...) at the end
BText wraps to the next line
CText overflows and causes a runtime error
DText is fully shown ignoring the container width
Attempts:
2 left
💡 Hint
Look at the overflow property used in the Text widget.
❓ lifecycle
advanced
2:00remaining
Text widget rebuild on state change
If a Text widget's style depends on a state variable, what happens when the state changes and setState() is called?
Flutter
class MyWidget extends StatefulWidget {
  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  bool isRed = true;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => setState(() => isRed = !isRed),
      child: Text('Tap me', style: TextStyle(color: isRed ? Colors.red : Colors.blue)),
    );
  }
}
AText color changes but only after hot reload
BText color never changes after first build
CApp crashes due to infinite rebuild loop
DText color toggles between red and blue on each tap
Attempts:
2 left
💡 Hint
setState triggers rebuild and updates UI with new state values.
🔧 Debug
expert
2:30remaining
Why does this Text widget not show styled text?
This Flutter code tries to style text with underline and color, but the text appears normal. What is the cause?
Flutter
Text('Styled Text', style: TextStyle(decoration: TextDecoration.underline, color: Colors.green))
AText widget ignores style property by default
BThe decoration value should be TextDecoration.underline, not underline
CColors.green is not a valid color constant
DTextStyle does not support decoration property
Attempts:
2 left
💡 Hint
Check how to specify underline decoration in TextStyle.

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

  1. Step 1: Understand the purpose of the Text widget

    The Text widget is designed to show text content on the screen in Flutter apps.
  2. 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.
  3. Final Answer:

    Displays words or sentences on the screen -> Option D
  4. 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

  1. Step 1: Recall how to style text color in Flutter

    Text color is set inside the style property using TextStyle with the color parameter.
  2. 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.
  3. Final Answer:

    Text('Hello', style: TextStyle(color: Colors.red)) -> Option B
  4. 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?
Text(
  'Hello Flutter',
  style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
  textAlign: TextAlign.center,
)
medium
A. Text 'Hello Flutter' right aligned, italic, size 20
B. Text 'Hello Flutter' left aligned, normal weight, size 14
C. Text 'Hello Flutter' centered, bold, and size 20
D. Text 'Hello Flutter' centered, normal weight, size 14

Solution

  1. Step 1: Analyze the style properties

    The fontWeight is set to bold and fontSize to 20, so text will be bold and large.
  2. Step 2: Check the textAlign property

    textAlign is TextAlign.center, so the text will be centered horizontally.
  3. Final Answer:

    Text 'Hello Flutter' centered, bold, and size 20 -> Option C
  4. Quick Check:

    Style and alignment match Text 'Hello Flutter' centered, bold, and size 20 [OK]
Hint: Check style and textAlign for appearance clues [OK]
Common Mistakes:
  • Ignoring textAlign property
  • Assuming default font size 14 without checking
  • Confusing fontWeight with fontStyle
4. Identify the error in this Flutter code snippet:
Text(
  'Welcome',
  style: TextStyle(fontSize: '20'),
)
medium
A. fontSize should be a double, not a string
B. Text widget cannot have style property
C. Missing comma after 'Welcome'
D. TextStyle cannot be used inside Text

Solution

  1. Step 1: Check the fontSize value type

    fontSize expects a number (double), but '20' is a string, causing a type error.
  2. Step 2: Validate other syntax parts

    Text widget supports style, commas are correct, and TextStyle is valid inside Text.
  3. Final Answer:

    fontSize should be a double, not a string -> Option A
  4. 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

  1. 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.
  2. 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.
  3. Final Answer:

    Text('Long text here', overflow: TextOverflow.ellipsis, maxLines: 1) -> Option A
  4. Quick Check:

    Ellipsis + maxLines 1 = Text('Long text here', overflow: TextOverflow.ellipsis, maxLines: 1) [OK]
Hint: Use overflow: ellipsis with maxLines: 1 for trailing dots [OK]
Common Mistakes:
  • Using overflow: clip instead of ellipsis
  • Not setting maxLines to limit lines
  • Setting maxLines to null disables line limit
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard