Bird
Raised Fist0
Fluttermobile~15 mins

Why everything in Flutter is a widget - Build It to Prove It

Choose your learning style10 modes available
Build: Widget Explanation Screen
This screen explains why everything in Flutter is a widget using simple text and examples.
Target UI
----------------------------------
| Widget Explanation Screen       |
|--------------------------------|
| Why everything in Flutter is a |
| widget:                       |
|                                |
| - Widgets build UI elements.   |
| - They are reusable blocks.     |
| - Everything is a widget: text, |
|   buttons, layout, even padding.|
|                                |
| [OK]                          |
----------------------------------
Display a title at the top
Show a short explanation in bullet points
Add an OK button at the bottom that closes the screen
Starter Code
Flutter
import 'package:flutter/material.dart';

class WidgetExplanationScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Widget Explanation Screen'),
      ),
      body: Padding(
        padding: EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // TODO: Add explanation text here
          ],
        ),
      ),
      // TODO: Add OK button here
    );
  }
}
Task 1
Task 2
Solution
Flutter
import 'package:flutter/material.dart';

class WidgetExplanationScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Widget Explanation Screen'),
      ),
      body: Padding(
        padding: EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text('Why everything in Flutter is a widget:', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
            SizedBox(height: 12),
            Text('• Widgets build UI elements.'),
            Text('• They are reusable blocks.'),
            Text('• Everything is a widget: text, buttons, layout, even padding.'),
          ],
        ),
      ),
      bottomNavigationBar: Padding(
        padding: EdgeInsets.all(16),
        child: ElevatedButton(
          onPressed: () {
            Navigator.of(context).pop();
          },
          child: Text('OK'),
        ),
      ),
    );
  }
}

This screen uses a Scaffold with an AppBar for the title. The main content is a Column inside Padding to show bullet points explaining why Flutter uses widgets everywhere. The bullet points are simple Text widgets. At the bottom, an ElevatedButton labeled 'OK' closes the screen using Navigator.pop(). This shows how Flutter treats everything as widgets, even text and buttons, making UI building consistent and flexible.

Final Result
Completed Screen
----------------------------------
| Widget Explanation Screen       |
|--------------------------------|
| Why everything in Flutter is a |
| widget:                       |
|                                |
| • Widgets build UI elements.    |
| • They are reusable blocks.      |
| • Everything is a widget: text, |
|   buttons, layout, even padding.|
|                                |
| [       OK       ]              |
----------------------------------
Tapping the OK button closes the screen and returns to the previous screen
Stretch Goal
Add a toggle to switch between light and dark mode on this screen
💡 Hint
Use a Switch widget in the AppBar and wrap your app with a Theme widget that changes based on the toggle

Practice

(1/5)
1. Why does Flutter use widgets for everything in the app?
easy
A. Because widgets replace the need for programming logic
B. Because widgets are only for text display
C. Because widgets are only used for animations
D. Because widgets are reusable building blocks for UI

Solution

  1. Step 1: Understand what widgets represent in Flutter

    Widgets are the basic units that build the user interface, from simple text to complex layouts.
  2. Step 2: Recognize the role of widgets in app design

    Widgets allow reuse and composition, making UI flexible and easy to build.
  3. Final Answer:

    Because widgets are reusable building blocks for UI -> Option D
  4. Quick Check:

    Widgets = reusable UI blocks [OK]
Hint: Widgets build UI pieces reusable everywhere [OK]
Common Mistakes:
  • Thinking widgets are only for text
  • Believing widgets replace all programming logic
  • Assuming widgets are only for animations
2. Which of the following is the correct way to create a simple text widget in Flutter?
easy
A. text('Hello World')
B. TextWidget('Hello World')
C. Text('Hello World')
D. TextView('Hello World')

Solution

  1. Step 1: Recall Flutter's text widget syntax

    The correct widget to display text is Text with a capital T and a string parameter.
  2. Step 2: Compare options to Flutter syntax

    Only Text('Hello World') uses the exact Flutter Text widget syntax.
  3. Final Answer:

    Text('Hello World') -> Option C
  4. Quick Check:

    Text widget syntax = Text('...') [OK]
Hint: Use capital T in Text widget for text display [OK]
Common Mistakes:
  • Using lowercase 'text' instead of 'Text'
  • Adding extra words like 'Widget' or 'View'
  • Confusing widget names with other frameworks
3. What will the following Flutter code display?
Center(
  child: Text('Welcome')
)
medium
A. Text 'Welcome' aligned to the center of the screen
B. Text 'Welcome' aligned to the top left
C. An error because Center cannot have a child
D. Text 'Welcome' aligned to the bottom right

Solution

  1. Step 1: Understand the Center widget role

    Center positions its child widget in the middle of the available space.
  2. Step 2: Analyze the child widget

    The child is a Text widget displaying 'Welcome'.
  3. Final Answer:

    Text 'Welcome' aligned to the center of the screen -> Option A
  4. Quick Check:

    Center widget centers child = Text 'Welcome' aligned to the center of the screen [OK]
Hint: Center widget centers whatever is inside it [OK]
Common Mistakes:
  • Thinking Center aligns to top left by default
  • Assuming Center cannot have children
  • Confusing Center with Align widget
4. Identify the error in this Flutter widget code:
Column(
  children: [
    Text('Hello'),
    Text('World')
  ]
)
medium
A. No error, code is correct
B. Column widget cannot have children
C. Text widgets must be wrapped in a Row
D. Missing a comma after the first Text widget

Solution

  1. Step 1: Check Column widget usage

    Column accepts a list of children widgets inside the children parameter.
  2. Step 2: Verify syntax correctness

    Commas separate list items; here commas are correctly placed after each Text widget.
  3. Final Answer:

    No error, code is correct -> Option A
  4. Quick Check:

    Column with children list syntax is correct [OK]
Hint: Children list in Column needs commas between widgets [OK]
Common Mistakes:
  • Forgetting commas between children
  • Thinking Column cannot have children
  • Believing Text must be inside Row
5. You want to create a screen with a blue background and centered white text saying 'Hello Flutter'. Which widget combination correctly achieves this?
hard
A. Container(color: Colors.blue, child: Text('Hello Flutter', color: Colors.white))
B. Scaffold(backgroundColor: Colors.blue, body: Center(child: Text('Hello Flutter', style: TextStyle(color: Colors.white))))
C. Center(backgroundColor: Colors.blue, child: Text('Hello Flutter', style: TextStyle(color: Colors.white)))
D. Text('Hello Flutter', style: TextStyle(color: Colors.white, backgroundColor: Colors.blue))

Solution

  1. Step 1: Identify the widget for screen background

    Scaffold provides a full screen structure and accepts backgroundColor.
  2. Step 2: Center the text and style it

    Center widget centers its child; Text widget styled with white color.
  3. Step 3: Check options for correct syntax and behavior

    Scaffold(backgroundColor: Colors.blue, body: Center(child: Text('Hello Flutter', style: TextStyle(color: Colors.white)))) uses Scaffold with backgroundColor and Center with styled Text correctly.
  4. Final Answer:

    Scaffold(backgroundColor: Colors.blue, body: Center(child: Text('Hello Flutter', style: TextStyle(color: Colors.white)))) -> Option B
  5. Quick Check:

    Scaffold + Center + styled Text = Scaffold(backgroundColor: Colors.blue, body: Center(child: Text('Hello Flutter', style: TextStyle(color: Colors.white)))) [OK]
Hint: Use Scaffold for background, Center to align, TextStyle for color [OK]
Common Mistakes:
  • Using Container without full screen coverage
  • Setting backgroundColor on Center widget (not supported)
  • Styling Text background instead of screen background
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