0
0
Fluttermobile~20 mins

MaterialApp and Scaffold in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MaterialApp and Scaffold Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What is the output of this Flutter code snippet?

Consider this Flutter app code:

MaterialApp(
  home: Scaffold(
    appBar: AppBar(title: Text('Hello')),
    body: Center(child: Text('Welcome')),
  ),
)

What will the user see on the screen?

Flutter
MaterialApp(
  home: Scaffold(
    appBar: AppBar(title: Text('Hello')),
    body: Center(child: Text('Welcome')),
  ),
)
AA screen with a top bar showing 'Hello' and centered text 'Welcome' below it.
BA blank screen with no text or app bar visible.
COnly the text 'Welcome' centered on a white background, no app bar.
DAn error because Scaffold cannot be used inside MaterialApp.
Attempts:
2 left
💡 Hint

Think about what Scaffold provides inside a MaterialApp.

lifecycle
intermediate
2:00remaining
What happens if you remove MaterialApp and use Scaffold directly?

Given this Flutter code:

Scaffold(
  appBar: AppBar(title: Text('Hi')),
  body: Center(child: Text('Content')),
)

What is the likely result when running this as the root widget?

AThe app crashes because MaterialApp is required for Scaffold.
BThe app runs normally with app bar and content displayed correctly.
CThe app runs but the app bar and material styles are missing or broken.
DThe app shows a blank white screen with no widgets visible.
Attempts:
2 left
💡 Hint

MaterialApp provides theme and material design context.

navigation
advanced
2:00remaining
How to navigate to a new screen using MaterialApp routes?

Given this MaterialApp setup:

MaterialApp(
  routes: {
    '/': (context) => HomeScreen(),
    '/second': (context) => SecondScreen(),
  },
)

Which code snippet correctly navigates from HomeScreen to SecondScreen?

ANavigator.pushNamed(context, '/second');
BNavigator.pop(context, '/second');
CNavigator.push(context, MaterialPageRoute(builder: (context) => SecondScreen()));
DNavigator.pushReplacementNamed(context, '/home');
Attempts:
2 left
💡 Hint

Use the named route defined in MaterialApp routes.

📝 Syntax
advanced
2:00remaining
What error does this Flutter code produce?

Analyze this Flutter snippet:

MaterialApp(
  home: Scaffold(
    appBar: AppBar(title Text('Title')),
    body: Text('Body'),
  ),
)

What error will occur?

ARuntimeError: Scaffold cannot have Text directly as body.
BNo error, code runs fine showing app bar and body text.
CTypeError: AppBar title expects a Widget but got a String.
DSyntaxError: Missing colon after 'title' in AppBar constructor.
Attempts:
2 left
💡 Hint

Check the AppBar constructor syntax carefully.

🧠 Conceptual
expert
2:00remaining
Why is MaterialApp usually the root widget in Flutter apps?

Choose the best explanation for why MaterialApp is typically the root widget in Flutter apps.

AMaterialApp is required to display any widgets on the screen in Flutter.
BMaterialApp provides material design theme, navigation, localization, and other app-wide features needed by widgets like Scaffold.
CMaterialApp automatically creates all screens and routes without developer input.
DMaterialApp replaces the need for Scaffold and other layout widgets.
Attempts:
2 left
💡 Hint

Think about what MaterialApp offers beyond just showing widgets.