Saron Tan
Saron Tan

Reputation: 23

How do you detect the host platform from flutter dart?

For UI that should differ slightly on iOS and Android, ?

Upvotes: -2

Views: 3920

Answers (3)

Aayush Kedawat
Aayush Kedawat

Reputation: 41

import 'dart:io' show Platform;

Now, you need to check whether you are on Web or Application.

if(kIsWeb) {
   Enter Web specific code here
} else {
   if(Platform.isIOS){
      Enter IOS specific code here.
   } else if (Platform.isAndroid){
      Enter Android specific code here.
   }
}

Platform has following options:

Platform.isAndroid
Platform.isFuchsia
Platform.isIOS
Platform.isLinux
Platform.isMacOS
Platform.isWindows

Upvotes: 4

Muhammad Atif Akram
Muhammad Atif Akram

Reputation: 1315

import 'dart:io' show Platform;

Now you can detect the platform by just doing

Platform.isIOS // for ios
Platform.isAndroid //for android

Upvotes: 4

Saron Tan
Saron Tan

Reputation: 23

import 'dart:io' show Platform;

if (Platform.isAndroid) {
  // Android-specific code
} else if (Platform.isIOS) {
  // iOS-specific code
}

Upvotes: 1

Related Questions