Sub topic 1
Material and Cupertino: two design languages, one framework
Flutter ships two widget libraries that imitate two platform design languages. Material targets Android and Google's design system. Cupertino targets iOS and Apple's Human Interface Guidelines. This chapter explains how they are built, where they differ, and why Flutter lets you use them side by side. The rest of the tutorial builds on that model.
Prerequisites
This chapter assumes you can:
- Read and write basic Dart syntax.
- Build screens from
StatelessWidgetandStatefulWidget, and update state withsetState. - Use
MaterialAppandScaffold. - Use
Navigatorand understand what aBuildContextis.
You need a working Flutter SDK. An emulator or desktop target is enough to run the example.
Why Flutter has two widget libraries
Flutter does not wrap native iOS or Android controls. It draws every pixel itself with its own rendering engine. A button on screen is a Flutter widget that paints a button shape, not a UIButton or an Android Button.
That design has a consequence. Nothing is automatically "native-looking". If an iOS user expects a translucent navigation bar, a swipe-back gesture and a rounded alert dialog, Flutter has to reproduce them in Dart code. The Cupertino library does that for iOS. The Material library does it for Material Design, which is also the default look of a new Flutter app.
Both libraries are ordinary Dart packages built on the same lower layers:
Because both libraries depend on the shared widgets layer, they compose. A Row, a Padding or a ListView works identically in either. Only the styled, platform-flavored widgets differ.
The two imports
You choose a library with an import:
import 'package:flutter/material.dart'; // Material widgets
import 'package:flutter/cupertino.dart'; // Cupertino widgetsEach import also re-exports the widgets layer, so you rarely import it directly. Importing both in one file is normal and does not cause name clashes, because the two libraries use different prefixes for their classes. Material names are plain (Switch, AppBar), and Cupertino names start with Cupertino (CupertinoSwitch, CupertinoNavigationBar).
What actually differs
The two languages differ in more than colors. They differ in structure, motion and conventions.
| Aspect | Material | Cupertino |
|---|---|---|
| Root app widget | `MaterialApp` | `CupertinoApp` |
| Screen scaffold | `Scaffold` with `AppBar` | `CupertinoPageScaffold` with `CupertinoNavigationBar` |
| Theme object | `ThemeData`, read with `Theme.of(context)` | `CupertinoThemeData`, read with `CupertinoTheme.of(context)` |
| Touch feedback | Ink ripple | Fade of the pressed control |
| Elevation | Shadows and surface tint | Mostly flat, with translucent bars |
| Dialogs | `AlertDialog` | `CupertinoAlertDialog`, `CupertinoActionSheet` |
| Switch | `Switch` | `CupertinoSwitch` |
| Date and option selection | Dialog-based pickers | Wheel-based `CupertinoPicker` and `CupertinoDatePicker` |
| Primary navigation | Drawer, `NavigationBar`, floating action button | Tab bar, back button with swipe-back |
Some of these rows hide real behavior. For example, a Cupertino navigation bar can collapse a large title as the page scrolls. A CupertinoPageRoute supports the iOS edge-swipe to go back. Those behaviors are part of what "feels like iOS", and later chapters cover them in detail.
A theme belongs to a library
Every styled widget reads its colors, text styles and shapes from a theme found through BuildContext. The two libraries use two separate theme objects:
- Material widgets call
Theme.of(context)and read aThemeData. - Cupertino widgets call
CupertinoTheme.of(context)and read aCupertinoThemeData.
MaterialApp installs a Theme. CupertinoApp installs a CupertinoTheme. A Cupertino widget placed under a MaterialApp still finds a Cupertino theme, because Flutter derives one from the Material ThemeData. This derivation is why mixing works at all. It is also why a mixed app can show a color you did not set explicitly. Chapter material on mixing returns to this.
Platform behavior is separate from platform look
Choosing MaterialApp does not mean your app behaves like Android on iOS. Several behaviors depend on the platform the app is running on, not on which library you imported:
- Scroll physics. Scrollables bounce at the edges on iOS and macOS, and show a glow or stretch effect on Android.
- Page transitions.
MaterialPageRouteuses a slide-from-the-right transition with swipe-back on iOS, and a different transition on Android, through the theme'spageTransitionsTheme. - Text selection and default typography. These follow the running platform.
So there are two independent questions. The first is which widget set draws the control. The second is which platform conventions apply to behavior. Flutter answers the second using TargetPlatform, an enum with values such as android, iOS, macOS, windows, linux and fuchsia. The platform-detection chapter shows how to read it correctly.
See both side by side
The following app shows the same two controls drawn by each library inside a single MaterialApp. You can paste it into lib/main.dart and run it on any device.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() => runApp(const ComparisonApp());
class ComparisonApp extends StatelessWidget {
const ComparisonApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(home: ComparisonPage());
}
}
class ComparisonPage extends StatefulWidget {
const ComparisonPage({super.key});
@override
State<ComparisonPage> createState() => _ComparisonPageState();
}
class _ComparisonPageState extends State<ComparisonPage> {
bool _on = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Two design languages')),
body: Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('Material'),
Switch(
value: _on,
onChanged: (value) => setState(() => _on = value),
),
FilledButton(onPressed: () {}, child: const Text('Save')),
const SizedBox(height: 32),
const Text('Cupertino'),
CupertinoSwitch(
value: _on,
onChanged: (value) => setState(() => _on = value),
),
CupertinoButton.filled(
onPressed: () {},
child: const Text('Save'),
),
],
),
),
);
}
}Both switches share the _on state, so toggling one moves the other. Notice the differences:
- The Material switch has a round thumb on a track, and the filled button has a ripple when pressed.
- The Cupertino switch is a green pill. The Cupertino button has no ripple and fades while pressed.
- The Cupertino button uses a more rounded shape.
Run the app on an Android emulator and on an iOS simulator. The widgets look identical across both. Only scroll and route behavior would change.
Common errors at this stage
- Using Material widgets without a Material ancestor. Widgets such as
TextField,ListTileandInkWellneed aMaterialwidget above them to paint ink effects.Scaffoldprovides one. OutsideScaffold, you may see "No Material widget found". Cupertino widgets do not require this. - Expecting
CupertinoAppto supply Material widgets with a theme. Under aCupertinoApp, there is noTheme. A Material widget that callsTheme.of(context)falls back to defaults, and some widgets assert. Wrap them in aThemeor aMaterial, or useMaterialApp. - Assuming Cupertino widgets only work on iOS. They run on every platform Flutter supports. Their system font and some colors are tuned for Apple platforms, so they look most correct there.
- Treating the choice as all-or-nothing. You can use
MaterialAppand placeCupertinoSwitchinside it. Mixing is supported and common.
Decision framing for the rest of the tutorial
There are three approaches, each with trade-offs:
- One design everywhere. Use only Material, or only Cupertino. This is the cheapest to build and test, and it gives a consistent brand. Users on the other platform may find some controls unfamiliar.
- Two apps' worth of UI. Build separate Material and Cupertino screens. This gives each platform full fidelity, but you maintain two trees of widgets.
- Adaptive widgets. Keep one structure and switch only the controls whose differences users notice, such as switches, dialogs and progress indicators. This balances fidelity and maintenance cost, and it is the approach this tutorial develops.
The next chapters cover the Cupertino building blocks first, then platform detection and adaptive widgets. The last chapter returns to the question of when adapting is worth the effort.
Exercise
An app uses MaterialApp and contains a CupertinoSwitch. The app runs on an iPhone. Name one thing that is drawn in the Material style and one behavior that follows iOS conventions without any code from you.
Show answer
The Scaffold, AppBar and any FilledButton are drawn in the Material style, because the app root is MaterialApp and Material widgets look the same on every platform. Scroll physics (edge bounce) and the MaterialPageRoute transition with swipe-back follow iOS conventions, because those depend on the running TargetPlatform rather than on the imported library.
Exercise
A teammate puts a TextField directly inside a CupertinoPageScaffold in a CupertinoApp, and the app throws "No Material widget found". Give two ways to fix it.
Show answer
Replace TextField with CupertinoTextField, which does not need a Material ancestor. Or wrap the TextField in a Material widget (and a Theme if it reads theme values), which supplies the ancestor it expects.