1

I need to customize web app whether it is used on laptop or phone, found ios or android detection, so would it work if I just did:

if (android or ios) {return phone version} else {computer version} ?

SOLUTION solutions below gave me an error, but this package helped me:

https://pub.dev/packages/universal_io

checkOS() {
    if (Platform.isAndroid || Platform.isIOS) {
      return PhoneVersion;
    } else {
      return ComputerVersion,
      );
    }
  }

or

log('os: ${Platform.operatingSystem}');
helloitsme2
  • 101
  • 6
  • See if this can answer your question: https://stackoverflow.com/questions/45924474/how-do-you-detect-the-host-platform-from-dart-code – Shubhamhackz Jan 23 '21 at 17:38

2 Answers2

3

You can use Platform class:

import 'dart:io';

bool isDesktop = (Platform.isWindows || Platform.isMacOS || Platform.isLinux);
bool isMobile = (Platform.isIOS || Platform.isAndroid);

also you can use kIsWeb:

import 'package:flutter/foundation.dart';

if (kIsWeb) {
   // HORIZONTAL LAYOUT
} else {
   // VERTICAL LAYOUT
} 
pasty
  • 380
  • 2
  • 8
0
if (Platform.isAndroid) {
  // Do Android case
} else {
  // Do other case
}

For retrieving more information about user's device, use packages like device_info.

fartem
  • 2,361
  • 2
  • 8
  • 20