The code uses Theme.textTheme.headline6 which is invalid because Theme is a class and requires context to access the current theme.
Step 2: Correct usage
The correct way is Theme.of(context).textTheme.headline6 to get the style from the current context.
Final Answer:
Missing context in Theme.of(context) call -> Option C
Quick Check:
Theme.of(context) needed to access theme [OK]
Hint: Always use Theme.of(context) to get theme data [OK]
Common Mistakes:
Using Theme without context
Assuming headline6 is invalid
Thinking Text needs TextSpan for style
5. You want to create a custom text theme where the subtitle1 style uses a font size of 18 and green color. Which code snippet correctly defines this inside ThemeData.textTheme?
hard
A. textTheme: TextTheme(subtitle1: TextStyle(font: 18, color: Colors.green))
B. textTheme: TextTheme(subtitle1: TextStyle(fontSize: 18, color: Colors.green))
C. textTheme: TextTheme(subtitle1: TextStyle(fontSize: 18, color: 'green'))
D. textTheme: TextTheme(subtitle1: TextStyle(size: 18, color: Colors.green))
Solution
Step 1: Identify correct TextStyle properties
The correct property for font size is fontSize and color must be a Color object like Colors.green.
Step 2: Evaluate each option
textTheme: TextTheme(subtitle1: TextStyle(fontSize: 18, color: Colors.green)) uses correct property names and values. textTheme: TextTheme(subtitle1: TextStyle(size: 18, color: Colors.green)) uses size which is invalid. textTheme: TextTheme(subtitle1: TextStyle(fontSize: 18, color: 'green')) uses a string for color instead of a Color object. textTheme: TextTheme(subtitle1: TextStyle(font: 18, color: Colors.green)) uses font which is invalid.
Final Answer:
textTheme: TextTheme(subtitle1: TextStyle(fontSize: 18, color: Colors.green)) -> Option B
Quick Check:
fontSize and Colors.green are correct [OK]
Hint: Use fontSize and Colors.green for size and color [OK]
Common Mistakes:
Using 'size' instead of fontSize
Passing color as string instead of Color object
Using invalid property names like font
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.