运行Flutter Web时的设备/浏览器详细信息

9nvpjoqh  于 2023-06-30  发布在  Flutter
关注(0)|答案(2)|浏览(174)

Flutter移动的(Android,iOS)有一个用于检索设备详细信息的包/插件,其中flutter应用程序正在运行,device_info。我需要的是一个包/插件来获取Flutter Web应用程序运行的设备/浏览器的详细信息。如果有人能指引我正确的方向,那就太好了。

gj3fmq9x

gj3fmq9x1#

从Flutter应用程序中获取当前设备信息,它适用于WEB以及桌面应用程序device_info_plus
你可以得到以下浏览器的详细信息'browserName': describeEnum(data.browserName),
更多的细节在这个例子中https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/example/lib/main.dart#L138

3pvhb19x

3pvhb19x2#

使用此库device_info_plus: ^9.0.2

import 'package:device_info_plus/device_info_plus.dart';

final deviceInfoPlugin = DeviceInfoPlugin();
final deviceInfo = await deviceInfoPlugin.deviceInfo;
final allInfo = deviceInfo.data;
print(allInfo.toString());

chrome 输出

{
  browserName: BrowserName.chrome,
  appCodeName: Mozilla,
  appName: Netscape,
  appVersion: 5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,
  likeGecko)Chrome/114.0.0.0Safari/537.36,
  deviceMemory: 8,
  language: en-US,
  languages: [
    en-US
  ],
  platform: Win32,
  product: Gecko,
  productSub: 20030107,
  userAgent: Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,
  likeGecko)Chrome/114.0.0.0Safari/537.36,
  vendor: GoogleInc.,
  vendorSub: ,
  hardwareConcurrency: 4,
  maxTouchPoints: 0
}

Firefox输出

{
  browserName: BrowserName.firefox,
  appCodeName: Mozilla,
  appName: Netscape,
  appVersion: 5.0(Windows),
  deviceMemory: null,
  language: en-US,
  languages: [
    en-US,
    en
  ],
  platform: Win32,
  product: Gecko,
  productSub: 20100101,
  userAgent: Mozilla/5.0(WindowsNT10.0;Win64;x64;rv: 109.0)Gecko/20100101Firefox/114.0,
  vendor: ,
  vendorSub: ,
  hardwareConcurrency: 4,
  maxTouchPoints: 0
}

Microsoft Edge输出

{
  browserName: BrowserName.edge,
  appCodeName: Mozilla,
  appName: Netscape,
  appVersion: 5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,
  likeGecko)Chrome/114.0.0.0Safari/537.36Edg/114.0.1823.58,
  deviceMemory: 8,
  language: en-US,
  languages: [
    en-US
  ],
  platform: Win32,
  product: Gecko,
  productSub: 20030107,
  userAgent: Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,
  likeGecko)Chrome/114.0.0.0Safari/537.36Edg/114.0.1823.58,
  vendor: GoogleInc.,
  vendorSub: ,
  hardwareConcurrency: 4,
  maxTouchPoints: 0
}

相关问题