Sub topic 16
When to Adapt and When to Keep One Design
Start with the product decision
This chapter assumes you know basic Dart, Flutter widgets, MaterialApp, Scaffold, Navigator, and BuildContext.
Flutter lets one codebase use Material widgets, Cupertino widgets, or both. Platform adaptation means changing appearance or behavior to match the device platform. A consistent design means keeping the same interface everywhere, even when the operating systems use different conventions.
Adaptation is useful when a platform convention affects usability, trust, or expected behavior. It is unnecessary when the difference is only decorative or when maintaining two versions would confuse users.
Use these questions before adding a platform branch:
- Does the platform convention change how users complete the task?
- Will users expect a native gesture, control, or navigation pattern?
- Does the app need a strong brand identity across platforms?
- Can the team test and maintain both variants?
- Could screen size or input type matter more than the operating system?
flowchart TD
A[Choose a UI decision] --> B{Does the platform change usability or behavior?}
B -->|Yes| C[Adapt the control or interaction]
B -->|No| D{Is one visual identity important?}
D -->|Yes| E[Keep one design]
D -->|No| F{Do size or input differences matter?}
F -->|Yes| G[Adapt layout or input behavior]
F -->|No| Ecaption: A decision path for choosing platform adaptation alt: A flowchart that asks whether platform changes usability, brand consistency, or layout needs before choosing adaptation.
Compare the trade-offs
| Choice | Strength | Common cost |
|---|---|---|
| Adapt by platform | Feels familiar to platform users | More code and more tests |
| Keep one design | Easier to learn and maintain | May feel unusual on one platform |
| Adapt by size and input | Handles phones, tablets, and desktop well | Requires responsive layout rules |
| Adapt everything | Matches many conventions | Creates visual and behavioral inconsistency |
Adapt high-impact interactions first. Examples include back navigation, tab bars, switches, date pickers, action sheets, and destructive confirmation dialogs. A Cupertino date picker can feel natural on iOS, while a Material date picker may be more familiar on Android.
Keep a consistent design for brand elements, content structure, colors, and workflows unless a platform requirement makes the difference valuable. Users should not lose the location or meaning of a feature simply because they changed devices.
Hide branches behind a small API
Do not repeat platform checks throughout every screen. Put the choice in a reusable widget. The screen then expresses intent, while the widget owns the platform detail.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() => runApp(const ExampleApp());
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Scaffold(
appBar: AppBar(title: const Text('Account')),
body: Center(
child: AdaptivePrimaryButton(
onPressed: () {},
child: const Text('Save'),
),
),
),
);
}
}
class AdaptivePrimaryButton extends StatelessWidget {
const AdaptivePrimaryButton({
super.key,
required this.onPressed,
required this.child,
});
final VoidCallback? onPressed;
final Widget child;
@override
Widget build(BuildContext context) {
final platform = Theme.of(context).platform;
final isApple = platform == TargetPlatform.iOS ||
platform == TargetPlatform.macOS;
if (isApple) {
return CupertinoButton.filled(
onPressed: onPressed,
child: child,
);
}
return FilledButton(
onPressed: onPressed,
child: child,
);
}
}Theme.of(context).platform is testable and works across Flutter targets. Avoid using dart:io platform checks in widgets. They do not work on the web and make widget tests harder to control.
Check failure modes
Adaptation can fail when branches drift. One platform might receive a new validation message while the other does not. A Cupertino control might also appear inside a Material layout with mismatched padding or typography.
Keep shared state, labels, and business logic outside the platform-specific widget. Test each branch by overriding ThemeData.platform. Also test behavior, not only widget types: tapping the control should produce the same result on every platform.
Exercise
A branded finance app uses the same account form on iOS and Android. Which parts are good candidates for adaptation?
Show answer
Adapt platform-sensitive controls such as navigation, switches, pickers, and confirmation dialogs. Keep the form fields, labels, validation rules, and account workflow shared unless usability research supports a larger difference.