Create platform-adaptive UIs with Material 3 and Cupertino widgets.
Material 3 (Material You)
Material 3 is the latest design system with dynamic color, updated components, and accessibility improvements.
Theme Configuration
// main.dart
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Movie App',
// Light theme
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.deepPurple, // Generates full palette
brightness: Brightness.light,
// Customize specific components
cardTheme: CardThemeData(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
inputDecorationTheme: InputDecorationTheme(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
filled: true,
),
),
// Dark theme
darkTheme: ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.deepPurple,
brightness: Brightness.dark,
),
// System preference
themeMode: ThemeMode.system,
home: const MovieListScreen(),
);
}
}Color Scheme
// Access colors throughout app
final colorScheme = Theme.of(context).colorScheme;
colorScheme.primary; // Brand color
colorScheme.onPrimary; // Text on primary
colorScheme.secondary; // Accent color
colorScheme.surface; // Card/background
colorScheme.onSurface; // Text on surface
colorScheme.error; // Error color
colorScheme.outline; // Borders
// Usage
Container(
color: colorScheme.surfaceContainerHighest,
child: Text(
'Content',
style: TextStyle(color: colorScheme.onSurface),
),
)Dynamic Color (Android 12+)
// Automatically uses user's wallpaper colors
// Enabled by default with useMaterial3: true
// Requires: compileSdkVersion 33+, targetSdkVersion 33+
// Customize dynamic color
ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.blue,
// Disable if needed
// visualDensity: VisualDensity.adaptivePlatformDensity,
);Material 3 Components
// Buttons
FilledButton(onPressed: () {}, child: Text('Primary'));
FilledButton.tonal(onPressed: () {}, child: Text('Secondary'));
OutlinedButton(onPressed: () {}, child: Text('Outlined'));
TextButton(onPressed: () {}, child: Text('Text'));
IconButton(onPressed: () {}, icon: Icon(Icons.favorite));
// Cards
Card(
elevation: 2,
child: Padding(
padding: EdgeInsets.all(16),
child: Column(children: [Text('Card content')]),
),
)
// Navigation
NavigationBar(
destinations: [
NavigationDestination(icon: Icon(Icons.home), label: 'Home'),
NavigationDestination(icon: Icon(Icons.search), label: 'Search'),
NavigationDestination(icon: Icon(Icons.person), label: 'Profile'),
],
selectedIndex: currentIndex,
onDestinationSelected: (index) => setState(() => currentIndex = index),
)
// Chips
FilterChip(
label: Text('Sci-Fi'),
selected: isSelected,
onSelected: (value) => setState(() => isSelected = value),
)
// Divider
Divider(height: 1, color: colorScheme.outlineVariant)Cupertino (iOS Style)
Cupertino widgets provide iOS-human-interface-guidelines-compliant UI.
Basic Setup
import 'package:flutter/cupertino.dart';
class CupertinoApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoApp(
title: 'Movie App',
theme: CupertinoThemeData(
brightness: Brightness.light,
primaryColor: CupertinoColors.systemBlue,
scaffoldBackgroundColor: CupertinoColors.systemGroupedBackground,
textTheme: CupertinoTextThemeData(
navLargeTitleTextStyle: TextStyle(fontSize: 34, fontWeight: FontWeight.bold),
),
),
home: CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: [
BottomNavigationBarItem(icon: Icon(CupertinoIcons.home), label: 'Home'),
BottomNavigationBarItem(icon: Icon(CupertinoIcons.search), label: 'Search'),
BottomNavigationBarItem(icon: Icon(CupertinoIcons.person), label: 'Profile'),
],
),
tabBuilder: (context, index) {
return CupertinoTabView(builder: (context) {
switch (index) {
case 0: return HomeScreen();
case 1: return SearchScreen();
case 2: return ProfileScreen();
}
});
},
),
);
}
}Cupertino Components
// Navigation bar
CupertinoNavigationBar(
middle: Text('Movies'),
trailing: CupertinoButton(
padding: EdgeInsets.zero,
child: Icon(CupertinoIcons.add),
onPressed: () {},
),
)
// List
CupertinoListSection.insetGrouped(
header: Text('Popular'),
children: movies.map((movie) =>
CupertinoListTile(
leading: Image.network(movie.posterUrl, width: 50, height: 75, fit: BoxFit.cover),
title: Text(movie.title),
subtitle: Text('${movie.year} • ${movie.rating}/10'),
trailing: Icon(CupertinoIcons.chevron_right),
onTap: () => navigateToDetail(movie),
),
).toList(),
)
// Form
CupertinoFormSection.insetGrouped(
header: Text('Account'),
children: [
CupertinoTextFormFieldRow(
prefix: Text('Email'),
placeholder: 'you@example.com',
keyboardType: TextInputType.emailAddress,
),
CupertinoTextFormFieldRow(
prefix: Text('Password'),
placeholder: '••••••••',
obscureText: true,
),
],
)
// Alert dialog
showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text('Delete Movie?'),
content: Text('This cannot be undone.'),
actions: [
CupertinoDialogAction(
child: Text('Cancel'),
onPressed: () => Navigator.pop(context),
),
CupertinoDialogAction(
isDestructiveAction: true,
child: Text('Delete'),
onPressed: () => { deleteMovie(); Navigator.pop(context); },
),
],
),
)
// Action sheet (bottom sheet)
showCupertinoModalPopup(
context: context,
builder: (context) => CupertinoActionSheet(
title: Text('Options'),
message: Text('Choose an action'),
actions: [
CupertinoActionSheetAction(
child: Text('Edit'),
onPressed: () => { editMovie(); Navigator.pop(context); },
),
CupertinoActionSheetAction(
isDestructiveAction: true,
child: Text('Delete'),
onPressed: () => { deleteMovie(); Navigator.pop(context); },
),
],
cancelButton: CupertinoActionSheetAction(
child: Text('Cancel'),
onPressed: () => Navigator.pop(context),
),
),
)
// Switch
CupertinoSwitch(
value: isEnabled,
onChanged: (value) => setState(() => isEnabled = value),
)
// Slider
CupertinoSlider(
value: rating,
onChanged: (value) => setState(() => rating = value),
min: 0,
max: 10,
divisions: 10,
)
// Date picker
showCupertinoModalPopup(
context: context,
builder: (context) => Container(
height: 300,
color: CupertinoColors.systemBackground,
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
initialDateTime: DateTime.now(),
onDateTimeChanged: (date) => selectedDate = date,
),
),
)Platform-Adaptive Widgets
Use widgets that automatically adapt to the platform.
Platform Detection
import 'dart:io' show Platform;
import 'package:flutter/foundation.dart' show kIsWeb;
// Runtime checks
if (Platform.isIOS) { /* iOS specific */ }
if (Platform.isAndroid) { /* Android specific */ }
if (Platform.isMacOS) { /* macOS specific */ }
if (Platform.isWindows) { /* Windows specific */ }
if (Platform.isLinux) { /* Linux specific */ }
if (kIsWeb) { /* Web specific */ }
// Widget-based (rebuilds on platform change)
Widget build(BuildContext context) {
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
return CupertinoWidget();
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.windows:
return MaterialWidget();
}
}Adaptive Widgets Package
flutter pub add adaptive_widgetsimport 'package:adaptive_widgets/adaptive_widgets.dart';
// Adaptive scaffold
AdaptiveScaffold(
body: (context) => MovieListScreen(),
bottomNavigationBuilder: (context) => AdaptiveBottomNavigation(
items: [
AdaptiveNavigationItem(
icon: Icons.home,
label: 'Home',
pageBuilder: (context) => HomeScreen(),
),
AdaptiveNavigationItem(
icon: Icons.search,
label: 'Search',
pageBuilder: (context) => SearchScreen(),
),
],
),
)
// Adaptive button
AdaptiveButton(
onPressed: () {},
child: Text('Submit'),
)
// Adaptive text field
AdaptiveTextField(
decoration: InputDecoration(labelText: 'Email'),
keyboardType: TextInputType.emailAddress,
)
// Adaptive dialog
showAdaptiveDialog(
context: context,
builder: (context) => AdaptiveAlertDialog(
title: Text('Confirm'),
content: Text('Are you sure?'),
actions: [
AdaptiveDialogAction(child: Text('Cancel'), onPressed: () => Navigator.pop(context)),
AdaptiveDialogAction(child: Text('OK'), onPressed: () => confirm()),
],
),
)Custom Platform-Adaptive Components
// Adaptive button
class AdaptiveButton extends StatelessWidget {
final VoidCallback? onPressed;
final Widget child;
final bool isPrimary;
const AdaptiveButton({
super.key,
required this.onPressed,
required this.child,
this.isPrimary = true,
});
@override
Widget build(BuildContext context) {
final isApple = Theme.of(context).platform == TargetPlatform.iOS ||
Theme.of(context).platform == TargetPlatform.macOS;
if (isApple) {
return CupertinoButton(
onPressed: onPressed,
color: isPrimary ? CupertinoColors.systemBlue : CupertinoColors.systemGrey5,
borderRadius: BorderRadius.circular(12),
child: child,
);
}
return FilledButton(
onPressed: onPressed,
style: FilledButton.styleFrom(
backgroundColor: isPrimary ? null : Theme.of(context).colorScheme.secondaryContainer,
foregroundColor: isPrimary ? null : Theme.of(context).colorScheme.onSecondaryContainer,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
child: child,
);
}
}
// Adaptive text field
class AdaptiveTextField extends StatelessWidget {
final TextEditingController? controller;
final String? label;
final String? hint;
final bool obscureText;
final TextInputType? keyboardType;
final ValueChanged<String>? onChanged;
const AdaptiveTextField({
super.key,
this.controller,
this.label,
this.hint,
this.obscureText = false,
this.keyboardType,
this.onChanged,
});
@override
Widget build(BuildContext context) {
final isApple = Theme.of(context).platform == TargetPlatform.iOS ||
Theme.of(context).platform == TargetPlatform.macOS;
if (isApple) {
return CupertinoTextField(
controller: controller,
placeholder: hint,
obscureText: obscureText,
keyboardType: keyboardType,
onChanged: onChanged,
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color: CupertinoColors.systemGrey6,
borderRadius: BorderRadius.circular(12),
),
);
}
return TextField(
controller: controller,
obscureText: obscureText,
keyboardType: keyboardType,
onChanged: onChanged,
decoration: InputDecoration(
labelText: label,
hintText: hint,
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
filled: true,
),
);
}
}
// Adaptive list tile
class AdaptiveListTile extends StatelessWidget {
final Widget? leading;
final Widget title;
final Widget? subtitle;
final Widget? trailing;
final VoidCallback? onTap;
const AdaptiveListTile({
super.key,
this.leading,
required this.title,
this.subtitle,
this.trailing,
this.onTap,
});
@override
Widget build(BuildContext context) {
final isApple = Theme.of(context).platform == TargetPlatform.iOS ||
Theme.of(context).platform == TargetPlatform.macOS;
if (isApple) {
return CupertinoListTile(
leading: leading,
title: title,
subtitle: subtitle,
trailing: trailing,
onTap: onTap,
);
}
return ListTile(
leading: leading,
title: title,
subtitle: subtitle,
trailing: trailing,
onTap: onTap,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
);
}
}Theme Extensions
// Custom theme extension for app-specific colors
@immutable
class AppColors extends ThemeExtension<AppColors> {
final Color movieCardBackground;
final Color ratingStar;
final Color genreChip;
const AppColors({
required this.movieCardBackground,
required this.ratingStar,
required this.genreChip,
});
@override
AppColors copyWith({
Color? movieCardBackground,
Color? ratingStar,
Color? genreChip,
}) {
return AppColors(
movieCardBackground: movieCardBackground ?? this.movieCardBackground,
ratingStar: ratingStar ?? this.ratingStar,
genreChip: genreChip ?? this.genreChip,
);
}
@override
AppColors lerp(ThemeExtension<AppColors>? other, double t) {
if (other is! AppColors) return this;
return AppColors(
movieCardBackground: Color.lerp(movieCardBackground, other.movieCardBackground, t)!,
ratingStar: Color.lerp(ratingStar, other.ratingStar, t)!,
genreChip: Color.lerp(genreChip, other.genreChip, t)!,
);
}
}
// Light theme extension
final lightAppColors = AppColors(
movieCardBackground: Colors.white,
ratingStar: Colors.amber,
genreChip: Colors.deepPurple.shade100,
);
// Dark theme extension
final darkAppColors = AppColors(
movieCardBackground: Colors.grey[900]!,
ratingStar: Colors.amber,
genreChip: Colors.deepPurple.shade900,
);
// Usage in ThemeData
ThemeData(
extensions: [lightAppColors],
darkTheme: ThemeData(extensions: [darkAppColors]),
)
// Access in widgets
final appColors = Theme.of(context).extension<AppColors>()!;
Container(color: appColors.movieCardBackground, child: ...)Try It
Run on iOS and Android simulators. Compare Material 3 vs Cupertino. Test theme switching.
# iOS Simulator
open -a Simulator
flutter run -d ios
# Android Emulator
flutter run -d android
# Toggle theme
# Settings → Appearance → Dark/LightBuild adaptive movie app
- Create Material 3 theme with custom color scheme
- Create Cupertino theme matching brand colors
- Build adaptive components (Button, TextField, ListTile, Dialog)
- Implement platform-specific navigation (NavBar vs TabBar)
- Add dynamic color support
- Test on iOS and Android
- Verify accessibility on both platforms
Material 3 provides dynamic color, updated components, and better accessibility. Cupertino gives native iOS look and feel. Use platform-adaptive widgets for consistent UX across platforms. Theme extensions allow custom colors without breaking theme system. Test on both platforms - don't assume one works like the other.
Resources
- Material 3: https://m3.material.io/
- Flutter Material 3: https://docs.flutter.dev/ui/material
- Cupertino: https://docs.flutter.dev/ui/cupertino
- Adaptive Widgets: https://pub.dev/packages/adaptive_widgets
- Theme Extensions: https://docs.flutter.dev/cookbook/design/themes