Flutter 检查应用程序是否在 iPad 或 iPhone 上运行

6 dart flutter

我在我的应用程序中使用振动,因为 iPad 不支持它,所以我想从我的应用程序中删除一个振动设备的按钮。

那么,我如何才能知道我的应用程序是在 iPad 还是 iPhone 上运行呢?

Luc*_*lli 12

device_info的用法是正确的,但是model应该使用属性:

Future<bool> isIpad() async{
  DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  IosDeviceInfo info = await deviceInfo.iosInfo;
  if (info.model.toLowerCase().contains("ipad")) {
    return true;
  }
  return false;
}
Run Code Online (Sandbox Code Playgroud)


小智 1

使用设备信息

Future<bool> isIpad() async{
  DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  IosDeviceInfo info = await deviceInfo.iosInfo;
  if (info.name.toLowerCase().contains("ipad")) {
    return true;
  }
  return false;
}
Run Code Online (Sandbox Code Playgroud)

  • 从技术上讲,这个答案是错误的。用户可以编辑设备的名称和“name”属性。 (8认同)