Platform Checking Material vs Cupertino Widgets

This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below.


*Enrollment provides full access to this course (and updates) for life.

Or Signup for Unlimited PRO Access

Example Code

file_type_dartlang main.dart
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'dart:io' show Platform;

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

class MyApp extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
   return MaterialApp(
     home: Scaffold(
       body: Center(
         child: Platform.isAndroid
             ? Switch(value: true, onChanged: (v) => null)
             : CupertinoSwitch(value: true, onChanged: (v) => null),
       ),
     ),
   );
 }
}

Q&A Chat