Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Widgets  ›  Lesson

Styled Widgets: Material and Cupertino

Styled Widgets 12 minFlutter ships two design-language widget sets, Material for Google's design system and Cupertino for Apple's iOS look, and a theme styles Material widgets from one place.

Styled Widgets: Material and Cupertino

Sprout works, but every screen is plain. You could colour each button by hand, and then change twenty places when the brand colour changes. Flutter instead ships complete, styled widget sets, and a theme that dresses them all from one spot.

The rule

Material for Google's look, Cupertino for Apple's; theme once, not per widget.

Material widgets follow Google's Material Design and work on every platform. An app built with them starts with MaterialApp:

MaterialApp(
  theme: ThemeData(
    colorScheme: ColorScheme.fromSeed(seedColor: Colors.green),
  ),
  home: Scaffold(
    appBar: AppBar(title: const Text('Sprout')),
    body: const PlantList(),
    floatingActionButton: FloatingActionButton(
      onPressed: addPlant,
      child: const Icon(Icons.add),
    ),
  ),
);

Scaffold gives the page structure: app bar, body, floating button, drawers, snack bars. ColorScheme.fromSeed builds a whole palette from one colour, and every Material widget reads its colours from it.

Cupertino widgets copy the look and feel of iOS: CupertinoApp, CupertinoPageScaffold, CupertinoNavigationBar, CupertinoButton, CupertinoSwitch. Choose them when an app should feel native on iPhone. Some Material widgets offer an adaptive constructor, such as Switch.adaptive, which draws an iOS switch on Apple platforms and a Material one elsewhere.

In your own widgets, read the theme rather than hard-coding colours:

final green = Theme.of(context).colorScheme.primary;

The shortcut

When you are tempted to set a colour or font on a single widget, ask "Should every widget like this look the same?"

Styling Sprout's buttonsStep 1 of 4
  1. All buttons should be green

    That is a theme decision. Set the seed colour in ThemeData, not on each button.

The trap is hard-coding Colors.green in thirty places. It works until the design changes or you add dark mode, and then every one of them is wrong.

Drills

Answer fast — trust the rule.

quick drill

Which widget provides an app bar, body and floating action button for a Material page?

quick drill

How do you make every Material button in Sprout green?

quick drill

Which widget set imitates the iOS look?

quick drill

Your custom card needs the app's primary colour. Best way to get it?

Remember

  • Material for Google's look, Cupertino for Apple's; theme once, not per widget.
  • Shortcut: if every widget of a kind should match, it belongs in the theme.
  • Trap: hard-coded colours scattered across widgets.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainRestyle Sprout in one place

Sprout's buttons and app bar should all use a green brand colour. Explain how you would do this with Material widgets without styling each widget separately, and when you might use Cupertino widgets instead.