【问题标题】:How to see what device is used?如何查看使用的是什么设备?
【发布时间】:2021-04-27 22:04:47
【问题描述】:

我需要自定义网络应用程序,无论是在笔记本电脑还是手机上使用,找到 ios 或 android 检测,如果我这样做,它会工作吗:

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

解决方案 下面的解决方案给了我一个错误,但这个包帮助了我:

https://pub.dev/packages/universal_io

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

log('os: ${Platform.operatingSystem}');

【问题讨论】:

标签: flutter dart flutter-web


【解决方案1】:

您可以使用平台类:

import 'dart:io';

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

你也可以使用 kIsWeb:

import 'package:flutter/foundation.dart';

if (kIsWeb) {
   // HORIZONTAL LAYOUT
} else {
   // VERTICAL LAYOUT
} 

【讨论】:

    【解决方案2】:
    if (Platform.isAndroid) {
      // Do Android case
    } else {
      // Do other case
    }
    

    要检索有关用户设备的更多信息,请使用 device_info 之类的包。

    【讨论】:

    • 我收到错误“不支持的操作:Platform._operatingSystem”
    • 你使用什么平台?
    • 我用的是windows。
    • 你还在面对这个问题吗?
    猜你喜欢
    • 2015-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    相关资源
    最近更新 更多