Checking Device Platform

Messages are passed between the client (UI) and host (platform) using platform channels as illustrated in this diagram:

platform channels flutter

Messages and responses are passed asynchronously, to ensure the user interface remains responsive.

Detecting the Current Platform – iOS or Android

import 'package:flutter/material.dart';

import 'package:flutter/foundation.dart';

 

void main() {

  runApp(const MyApp());

}

 

class MyApp extends StatelessWidget {

  const MyApp({Keykey}) : super(keykey);

 

  @override

  Widget build(BuildContext context) {

    return MaterialApp(

      title'responsive and adaptive',

      themeThemeData(

        primarySwatchColors.blue,

      ),

      homeconst MyHomePage(),

    );

  }

}

 

class MyHomePage extends StatelessWidget {

  const MyHomePage({Keykey}) : super(keykey);

 

  @override

  Widget build(BuildContext context) {

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

    return Scaffold(

      appBarAppBar(

        title:

            Text(platform == TargetPlatform.iOS ? 'iOS' : 'Android or Other'),

      ),

    );

  }

}



On Android

flutter android

On iOS

flutter iOS