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}');
1

2 Answers 2

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
} 
0
if (Platform.isAndroid) {
  // Do Android case
} else {
  // Do other case
}

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

4
  • I got an error 'Unsupported operation: Platform._operatingSystem' Commented Jan 24, 2021 at 6:31
  • What platform do you use?
    – fartem
    Commented Jan 24, 2021 at 6:32
  • i use windows . Commented Feb 20, 2021 at 11:44
  • Are you still faced with this question?
    – fartem
    Commented Feb 20, 2021 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.