medium.com 7 min read Original Source

Flutter Lesson 6 : Material vs Cupertino Widgets

Now that we’ve learned how to debug, inspect and understand what Flutter is doing under the hood, it’s time to shift our focus back to what users actually see, the visual experience. Flutter’s biggest strength is its ability to feel perfectly at home on both Android and iOS without writing two separate apps.

In this lesson, we’ll explore the two design languages Flutter supports: Material (Google’s design system for Android) and Cupertino (Apple’s design style for iOS). You’ll see how Flutter makes it surprisingly easy to build screens that look native on both platforms, and how you can adapt designs depending on the device.

Think of this lesson as learning Flutter’s “visual personality”, the styles, components, and UI rules that shape how your app feels in a user’s hands. Let’s dive in.

Section 1 : Material Design (Android)?

Let’s start building a simple Material-style Profile Card. This will show a photo, name, bio, and an action button, all using core Material widgets (Card, CircleAvatar, ElevatedButton). Paste this into lib/main.dart of a new Flutter project and run it, it’s runnable as is.

runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Profile Card – Material Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.blue),
home: Scaffold(
appBar: AppBar(title: Text('Profile Card (Material)')),
body: Center(child: MaterialProfileCard()),
),
);
}
}

class MaterialProfileCard extends StatelessWidget {
// Use a network image by default so this runs immediately.
final String networkImage =
'https://images.unsplash.com/photo-1544005313-94ddf0286df2?w=800&q=80';

// Optional: local path example (the uploaded image exists at a runtime path)
// To use a local file (desktop/emulator), uncomment and use Image.file
// final String localPath = '/mnt/data/A_2D_digital_graphic_design_serves_as_a_cover_slid.png';

@override
Widget build(BuildContext context) {
return Card(
elevation: 6,
margin: EdgeInsets.symmetric(horizontal: 20),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(18.0),
child: Column(
mainAxisSize: MainAxisSize.min, // wrap content height
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Avatar
CircleAvatar(
radius: 42,
backgroundImage: NetworkImage(networkImage),
// To use a local file (optional), replace the above with:
// backgroundImage: FileImage(File(localPath)),
),
SizedBox(height: 12),

// Name
Text(
'Asha Verma',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),

// Subtitle / small bio
SizedBox(height: 6),
Text(
'Mobile developer • Flutter enthusiast • Music app maker',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 14, color: Colors.black54),
),

SizedBox(height: 14),

// Action row
Row(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton.icon(
onPressed: () {
// simple feedback: show a SnackBar
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Followed Asha')),
);
},
icon: Icon(Icons.person_add),
label: Text('Follow'),
),
SizedBox(width: 12),
OutlinedButton(
onPressed: () {
// show details or navigate — kept simple here
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text('Profile'),
content: Text('Open profile details (demo).'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text('Close'),
)
],
),
);
},
child: Text('View'),
),
],
),
],
),
),
);
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

import 'dart:io'; // only needed if using local file image (optional)
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Profile Card - Material Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primarySwatch: Colors.blue),
      home: Scaffold(
        appBar: AppBar(title: Text('Profile Card (Material)')),
        body: Center(child: MaterialProfileCard()),
      ),
    );
  }
}

class MaterialProfileCard extends StatelessWidget {
  // Use a network image by default so this runs immediately.
  final String networkImage =
      'https://images.unsplash.com/photo-1544005313-94ddf0286df2?w=800&q=80';

  // Optional: local path example (the uploaded image exists at a runtime path)
  // To use a local file (desktop/emulator), uncomment and use Image.file
  // final String localPath = '/mnt/data/A_2D_digital_graphic_design_serves_as_a_cover_slid.png';

  @override
  Widget build(BuildContext context) {
    return Card(
      elevation: 6,
      margin: EdgeInsets.symmetric(horizontal: 20),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
      child: Padding(
        padding: const EdgeInsets.all(18.0),
        child: Column(
          mainAxisSize: MainAxisSize.min, // wrap content height
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            // Avatar
            CircleAvatar(
              radius: 42,
              backgroundImage: NetworkImage(networkImage),
              // To use a local file (optional), replace the above with:
              // backgroundImage: FileImage(File(localPath)),
            ),
            SizedBox(height: 12),

            // Name
            Text(
              'Asha Verma',
              style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
            ),

            // Subtitle / small bio
            SizedBox(height: 6),
            Text(
              'Mobile developer • Flutter enthusiast • Music app maker',
              textAlign: TextAlign.center,
              style: TextStyle(fontSize: 14, color: Colors.black54),
            ),

            SizedBox(height: 14),

            // Action row
            Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                ElevatedButton.icon(
                  onPressed: () {
                    // simple feedback: show a SnackBar
                    ScaffoldMessenger.of(context).showSnackBar(
                      SnackBar(content: Text('Followed Asha')),
                    );
                  },
                  icon: Icon(Icons.person_add),
                  label: Text('Follow'),
                ),
                SizedBox(width: 12),
                OutlinedButton(
                  onPressed: () {
                    // show details or navigate — kept simple here
                    showDialog(
                      context: context,
                      builder: (_) => AlertDialog(
                        title: Text('Profile'),
                        content: Text('Open profile details (demo).'),
                        actions: [
                          TextButton(
                            onPressed: () => Navigator.pop(context),
                            child: Text('Close'),
                          )
                        ],
                      ),
                    );
                  },
                  child: Text('View'),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
import 'dart:io'; // only needed if using local file image (optional)
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Profile Card - Material Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primarySwatch: Colors.blue),
      home: Scaffold(
        appBar: AppBar(title: Text('Profile Card (Material)')),
        body: Center(child: MaterialProfileCard()),
      ),
    );
  }
}

class MaterialProfileCard extends StatelessWidget {
  // Use a network image by default so this runs immediately.
  final String networkImage =
      'https://images.unsplash.com/photo-1544005313-94ddf0286df2?w=800&q=80';

  // Optional: local path example (the uploaded image exists at a runtime path)
  // To use a local file (desktop/emulator), uncomment and use Image.file
  // final String localPath = '/mnt/data/A_2D_digital_graphic_design_serves_as_a_cover_slid.png';

  @override
  Widget build(BuildContext context) {
    return Card(
      elevation: 6,
      margin: EdgeInsets.symmetric(horizontal: 20),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
      child: Padding(
        padding: const EdgeInsets.all(18.0),
        child: Column(
          mainAxisSize: MainAxisSize.min, // wrap content height
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            // Avatar
            CircleAvatar(
              radius: 42,
              backgroundImage: NetworkImage(networkImage),
              // To use a local file (optional), replace the above with:
              // backgroundImage: FileImage(File(localPath)),
            ),
            SizedBox(height: 12),

            // Name
            Text(
              'Asha Verma',
              style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
            ),

            // Subtitle / small bio
            SizedBox(height: 6),
            Text(
              'Mobile developer • Flutter enthusiast • Music app maker',
              textAlign: TextAlign.center,
              style: TextStyle(fontSize: 14, color: Colors.black54),
            ),

            SizedBox(height: 14),

            // Action row
            Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                ElevatedButton.icon(
                  onPressed: () {
                    // simple feedback: show a SnackBar
                    ScaffoldMessenger.of(context).showSnackBar(
                      SnackBar(content: Text('Followed Asha')),
                    );
                  },
                  icon: Icon(Icons.person_add),
                  label: Text('Follow'),
                ),
                SizedBox(width: 12),
                OutlinedButton(
                  onPressed: () {
                    // show details or navigate — kept simple here
                    showDialog(
                      context: context,
                      builder: (_) => AlertDialog(
                        title: Text('Profile'),
                        content: Text('Open profile details (demo).'),
                        actions: [
                          TextButton(
                            onPressed: () => Navigator.pop(context),
                            child: Text('Close'),
                          )
                        ],
                      ),
                    );
                  },
                  child: Text('View'),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
  • Card + Padding + Column create a neat grouped UI element, Material’s common pattern for grouped content.
  • CircleAvatar holds the profile image (use NetworkImage for an instant demo).
  • ElevatedButton and OutlinedButton show Material actions with built-in ripples and accessibility behaviors.
  • ScaffoldMessenger + SnackBar demonstrate lightweight in-app notifications in Material apps.
  • Layout choices: mainAxisSize: MainAxisSize.min keeps the card compact; crossAxisAlignment centers children horizontally.

Section 2 : Cupertino Profile Card (iOS)

Now that we’ve built the Material version of our Profile Card, let’s recreate the same UI using Cupertino widgets. This helps students see the difference in design philosophy — softer edges, flatter surfaces, subtle animations, and that classic iOS feel.

Just like the Material demo, this code is fully runnable. You can paste it into main.dart of a new project or replace the previous demo’s home: widget to jump between Material and Cupertino versions.

runApp(MyCupertinoApp());

class MyCupertinoApp extends StatelessWidget {
const MyCupertinoApp({super.key});

@override
Widget build(BuildContext context) {
// don't mark the app const here — children include runtime widgets (Image.network, errorBuilder, etc.)
return CupertinoApp(
debugShowCheckedModeBanner: false,
home: CupertinoProfilePage(),
);
}
}

class CupertinoProfilePage extends StatelessWidget {
const CupertinoProfilePage({super.key});

// Default network image so we never pass null
static const String defaultImage =
'https://images.unsplash.com/photo-1544005313-94ddf0286df2?w=800&q=80';

@override
Widget build(BuildContext context) {
// avoid const here as well
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(middle: Text('Profile (Cupertino)')),
child: const SafeArea(
child: Center(child: CupertinoProfileCard()),
),
);
}
}

class CupertinoProfileCard extends StatelessWidget {
// Make imageUrl optional and fall back to default inside the widget
final String? imageUrl;
const CupertinoProfileCard({super.key, this.imageUrl});

@override
Widget build(BuildContext context) {
final String img = imageUrl ?? CupertinoProfilePage.defaultImage;

return Container(
width: 320,
padding: const EdgeInsets.all(18),
decoration: BoxDecoration(
color: CupertinoColors.systemGrey6,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
blurRadius: 8,
spreadRadius: 1,
// withOpacity is runtime, so keep it non-const (decoration is non-const already)
color: CupertinoColors.systemGrey3.withOpacity(0.5),
)
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Profile image – Image.network won't be given null url
ClipRRect(
borderRadius: BorderRadius.circular(50),
child: Image.network(
img,
height: 100,
width: 100,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
// If network fails, show a simple placeholder
return Container(
height: 100,
width: 100,
color: CupertinoColors.systemGrey,
child: const Icon(CupertinoIcons.person, size: 48, color: Colors.white),
);
},
),
),
const SizedBox(height: 12),
const Text('Asha Verma',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600, color: CupertinoColors.black)),
const SizedBox(height: 6),
const Text(
'iOS-friendly UI • Flutter learner • Creative thinker',
style: TextStyle(fontSize: 14, color: CupertinoColors.systemGrey),
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CupertinoButton.filled(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
child: const Text('Follow'),
onPressed: () {
if (!context.mounted) return;
showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: const Text('Followed!'),
content: const Text('You are now following Asha.'),
actions: [
CupertinoDialogAction(
onPressed: () => Navigator.of(context).pop(),
child: const Text('OK'),
),
],
),
);
},
),
const SizedBox(width: 12),
CupertinoButton(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
child: const Text('View'),
onPressed: () {
if (!context.mounted) return;
showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: const Text('Profile'),
content: const Text('Open profile details (Cupertino demo).'),
actions: [
CupertinoDialogAction(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Close'),
),
],
),
);
},
),
],
),
],
),
);
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; // kept for Icons & Colors fallback

void main() => runApp(MyCupertinoApp());

class MyCupertinoApp extends StatelessWidget {
  const MyCupertinoApp({super.key});

  @override
  Widget build(BuildContext context) {
    // don't mark the app const here — children include runtime widgets (Image.network, errorBuilder, etc.)
    return CupertinoApp(
      debugShowCheckedModeBanner: false,
      home: CupertinoProfilePage(),
    );
  }
}

class CupertinoProfilePage extends StatelessWidget {
  const CupertinoProfilePage({super.key});

  // Default network image so we never pass null
  static const String defaultImage =
      'https://images.unsplash.com/photo-1544005313-94ddf0286df2?w=800&q=80';

  @override
  Widget build(BuildContext context) {
    // avoid const here as well
    return CupertinoPageScaffold(
      navigationBar: const CupertinoNavigationBar(middle: Text('Profile (Cupertino)')),
      child: const SafeArea(
        child: Center(child: CupertinoProfileCard()),
      ),
    );
  }
}

class CupertinoProfileCard extends StatelessWidget {
  // Make imageUrl optional and fall back to default inside the widget
  final String? imageUrl;
  const CupertinoProfileCard({super.key, this.imageUrl});

  @override
  Widget build(BuildContext context) {
    final String img = imageUrl ?? CupertinoProfilePage.defaultImage;

    return Container(
      width: 320,
      padding: const EdgeInsets.all(18),
      decoration: BoxDecoration(
        color: CupertinoColors.systemGrey6,
        borderRadius: BorderRadius.circular(16),
        boxShadow: [
          BoxShadow(
            blurRadius: 8,
            spreadRadius: 1,
            // withOpacity is runtime, so keep it non-const (decoration is non-const already)
            color: CupertinoColors.systemGrey3.withOpacity(0.5),
          )
        ],
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          // Profile image - Image.network won't be given null url
          ClipRRect(
            borderRadius: BorderRadius.circular(50),
            child: Image.network(
              img,
              height: 100,
              width: 100,
              fit: BoxFit.cover,
              errorBuilder: (context, error, stackTrace) {
                // If network fails, show a simple placeholder
                return Container(
                  height: 100,
                  width: 100,
                  color: CupertinoColors.systemGrey,
                  child: const Icon(CupertinoIcons.person, size: 48, color: Colors.white),
                );
              },
            ),
          ),
          const SizedBox(height: 12),
          const Text('Asha Verma',
              style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600, color: CupertinoColors.black)),
          const SizedBox(height: 6),
          const Text(
            'iOS-friendly UI • Flutter learner • Creative thinker',
            style: TextStyle(fontSize: 14, color: CupertinoColors.systemGrey),
            textAlign: TextAlign.center,
          ),
          const SizedBox(height: 16),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              CupertinoButton.filled(
                padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
                child: const Text('Follow'),
                onPressed: () {
                  if (!context.mounted) return;
                  showCupertinoDialog<void>(
                    context: context,
                    builder: (context) => CupertinoAlertDialog(
                      title: const Text('Followed!'),
                      content: const Text('You are now following Asha.'),
                      actions: [
                        CupertinoDialogAction(
                          onPressed: () => Navigator.of(context).pop(),
                          child: const Text('OK'),
                        ),
                      ],
                    ),
                  );
                },
              ),
              const SizedBox(width: 12),
              CupertinoButton(
                padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
                child: const Text('View'),
                onPressed: () {
                  if (!context.mounted) return;
                  showCupertinoDialog<void>(
                    context: context,
                    builder: (context) => CupertinoAlertDialog(
                      title: const Text('Profile'),
                      content: const Text('Open profile details (Cupertino demo).'),
                      actions: [
                        CupertinoDialogAction(
                          onPressed: () => Navigator.of(context).pop(),
                          child: const Text('Close'),
                        ),
                      ],
                    ),
                  );
                },
              ),
            ],
          ),
        ],
      ),
    );
  }
}
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; // kept for Icons & Colors fallback

void main() => runApp(MyCupertinoApp());

class MyCupertinoApp extends StatelessWidget {
  const MyCupertinoApp({super.key});

  @override
  Widget build(BuildContext context) {
    // don't mark the app const here — children include runtime widgets (Image.network, errorBuilder, etc.)
    return CupertinoApp(
      debugShowCheckedModeBanner: false,
      home: CupertinoProfilePage(),
    );
  }
}

class CupertinoProfilePage extends StatelessWidget {
  const CupertinoProfilePage({super.key});

  // Default network image so we never pass null
  static const String defaultImage =
      'https://images.unsplash.com/photo-1544005313-94ddf0286df2?w=800&q=80';

  @override
  Widget build(BuildContext context) {
    // avoid const here as well
    return CupertinoPageScaffold(
      navigationBar: const CupertinoNavigationBar(middle: Text('Profile (Cupertino)')),
      child: const SafeArea(
        child: Center(child: CupertinoProfileCard()),
      ),
    );
  }
}

class CupertinoProfileCard extends StatelessWidget {
  // Make imageUrl optional and fall back to default inside the widget
  final String? imageUrl;
  const CupertinoProfileCard({super.key, this.imageUrl});

  @override
  Widget build(BuildContext context) {
    final String img = imageUrl ?? CupertinoProfilePage.defaultImage;

    return Container(
      width: 320,
      padding: const EdgeInsets.all(18),
      decoration: BoxDecoration(
        color: CupertinoColors.systemGrey6,
        borderRadius: BorderRadius.circular(16),
        boxShadow: [
          BoxShadow(
            blurRadius: 8,
            spreadRadius: 1,
            // withOpacity is runtime, so keep it non-const (decoration is non-const already)
            color: CupertinoColors.systemGrey3.withOpacity(0.5),
          )
        ],
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          // Profile image - Image.network won't be given null url
          ClipRRect(
            borderRadius: BorderRadius.circular(50),
            child: Image.network(
              img,
              height: 100,
              width: 100,
              fit: BoxFit.cover,
              errorBuilder: (context, error, stackTrace) {
                // If network fails, show a simple placeholder
                return Container(
                  height: 100,
                  width: 100,
                  color: CupertinoColors.systemGrey,
                  child: const Icon(CupertinoIcons.person, size: 48, color: Colors.white),
                );
              },
            ),
          ),
          const SizedBox(height: 12),
          const Text('Asha Verma',
              style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600, color: CupertinoColors.black)),
          const SizedBox(height: 6),
          const Text(
            'iOS-friendly UI • Flutter learner • Creative thinker',
            style: TextStyle(fontSize: 14, color: CupertinoColors.systemGrey),
            textAlign: TextAlign.center,
          ),
          const SizedBox(height: 16),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              CupertinoButton.filled(
                padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
                child: const Text('Follow'),
                onPressed: () {
                  if (!context.mounted) return;
                  showCupertinoDialog<void>(
                    context: context,
                    builder: (context) => CupertinoAlertDialog(
                      title: const Text('Followed!'),
                      content: const Text('You are now following Asha.'),
                      actions: [
                        CupertinoDialogAction(
                          onPressed: () => Navigator.of(context).pop(),
                          child: const Text('OK'),
                        ),
                      ],
                    ),
                  );
                },
              ),
              const SizedBox(width: 12),
              CupertinoButton(
                padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
                child: const Text('View'),
                onPressed: () {
                  if (!context.mounted) return;
                  showCupertinoDialog<void>(
                    context: context,
                    builder: (context) => CupertinoAlertDialog(
                      title: const Text('Profile'),
                      content: const Text('Open profile details (Cupertino demo).'),
                      actions: [
                        CupertinoDialogAction(
                          onPressed: () => Navigator.of(context).pop(),
                          child: const Text('Close'),
                        ),
                      ],
                    ),
                  );
                },
              ),
            ],
          ),
        ],
      ),
    );
  }
}

This demo shows students how Flutter can recreate native iOS design using Cupertino widgets while keeping their code structure almost identical to the Material version. Here’s what the code teaches in simple terms:

1. Understanding CupertinoApp & Cupertino Scaffolding

  • CupertinoApp is the iOS equivalent of MaterialApp.
  • CupertinoPageScaffold serves as the iOS page layout, paired with a CupertinoNavigationBar. Students see how swapping the root widgets instantly switches the app’s visual language.

2. Building iOS style UI With Cupertino Widgets

  • The profile card uses classic iOS elements: soft greys, rounded corners, light shadows, and subtle contrast.
  • CupertinoButton and CupertinoButton.filled match native iOS button design and animations. This shows how design philosophy shifts while structure remains the same.

3. Error safe Network Images

  • The image section uses a default URL, ensuring it never passes a null value.
  • errorBuilder displays a fallback avatar if the network image fails.
    Students learn how to write robust UI that doesn’t crash from missing data.

4. Using Non const Widgets Where Required

  • Some constructors (like Image.network or colors with .withOpacity) must run at runtime.
  • The code demonstrates when and why you avoid using const, an important Flutter skill many beginners overlook.

5. Safe Dialog Handling With context.mounted

  • Before showing a dialog, the code checks if (!context.mounted) return;.
  • This teaches safe UI operations: never show dialogs on a disposed widget.

6. Simple Layout Using Container + Column

  • The layout stays approachable: a Container with padding, Column for vertical stacking, SizedBox for spacing.
  • It reinforces that Cupertino styling doesn’t require complex layouts, the same Flutter layout skills apply everywhere.

7. Visual Difference Between Material and Cupertino

Because you built the same card in Lesson 6 Section 1 (Material version) and here again in Cupertino style:

  • Students immediately see how Flutter keeps logic the same but changes design language based on the widget set they use.
  • This prepares them for adaptive UI design later, choosing styles based on platform.

Section 3 : Platform Detection

Now that we’ve built both the Material and Cupertino versions of our profile card, let’s make the app smart enough to choose the right design automatically. Flutter gives us simple ways to detect whether the app is running on Android or iOS, so we can load the proper UI and make the experience feel native on each device.

Platform detection matters because users instantly recognize their platform’s design language, Android users expect Material ripples and floating buttons, while iOS users feel more at home with Cupertino’s clean, soft interactions.

Here’s a short runnable snippet you can place inside your home: parameter in MaterialApp or CupertinoApp to load UI conditionally:

Add this inside your MyApp widget (replace your current home: line):

import 'dart:io' show Platform; // add this at the top

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,

      // 👇 This is the platform-based conditional UI
      home: Platform.isIOS
          ? CupertinoProfilePage()
          : MaterialProfilePage(),
    );
  }
}
import 'dart:io' show Platform; // add this at the top

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,

      // 👇 This is the platform-based conditional UI
      home: Platform.isIOS
          ? CupertinoProfilePage()
          : MaterialProfilePage(),
    );
  }
}

If you want to detect platform using Flutter’s theme instead of dart:io, here’s the alternative:

final platform = Theme.of(context).platform;

home: platform == TargetPlatform.iOS
    ? CupertinoProfilePage()
    : MaterialProfilePage();
final platform = Theme.of(context).platform;

home: platform == TargetPlatform.iOS
    ? CupertinoProfilePage()
    : MaterialProfilePage();

Section 4 : Mixing Material & Cupertino in One App

Before we wrap up this lesson, it’s worth knowing that Flutter doesn’t lock you into just one design system. Even though we usually stick to Material for Android and Cupertino for iOS, Flutter lets you mix both styles inside the same app if the situation calls for it. It’s not something you’ll do often, but it can be useful for hybrid apps, internal dashboards, or when a specific widget behaves better in one style than the other.

For example, you might use a Cupertino-style date picker inside a Material app because it feels cleaner for your use case. Or you might use a Material SnackBar inside a Cupertino scaffold to quickly show feedback. Flutter doesn’t stop you — both libraries coexist beautifully.

The key is to always maintain a consistent UX. A button that looks iOS-like next to a strongly Material-style element can feel out of place unless done intentionally. Use this flexibility wisely, and only when it genuinely improves the user experience.

Here’s a tiny snippet showing how easily Flutter lets you blend them:

// Example: Using a Cupertino button inside a Material screen

Scaffold(
  appBar: AppBar(title: Text('Hybrid UI')),
  body: Center(
    child: CupertinoButton.filled(
      child: Text('Cupertino Action'),
      onPressed: () {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(content: Text('This is a Material SnackBar')),
        );
      },
    ),
  ),
);
// Example: Using a Cupertino button inside a Material screen

Scaffold(
  appBar: AppBar(title: Text('Hybrid UI')),
  body: Center(
    child: CupertinoButton.filled(
      child: Text('Cupertino Action'),
      onPressed: () {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(content: Text('This is a Material SnackBar')),
        );
      },
    ),
  ),
);

This blends both systems seamlessly: a CupertinoButton triggers a Material SnackBar, all in the same widget tree.

Flutter gives you the freedom to mix when needed, auto-detect when appropriate, and stay consistent when it matters. With Material, Cupertino, and your new understanding of platform adaptation, you now have the tools to design UI that feels native on any device.

Save this lecture and read full Flutter list of chapters here.