我一直在尝试获取Android设备版本(例如11、12)。我一直在尝试只获取数字
这就是我到目前为止所做的
void checkVersion(){
print(Platform.operatingSystemVersion); // it prints "sdk_gphone64_arm64-userdebug 12 S2B2.211203.006 8015633 dev-keys"
// I'm able to fetch the version number by splitting the string
// but the problem is that format of above string will vary by
// operating system, so not suitable for parsing
int platformVersion = int.parse(Platform.operatingSystemVersion.split(' ')[1]); it prints '12'
}
Run Code Online (Sandbox Code Playgroud)
使用该device_info_plus插件并通过以下代码片段获取 Android、iOS、macOS、Linux 版本:
Future<String> _getOsVersion() async {
final deviceInfo = DeviceInfoPlugin();
if (Platform.isAndroid) {
final info = await deviceInfo.androidInfo;
return info.version.release ?? 'Unknown';
}
if (Platform.isIOS) {
final info = await deviceInfo.iosInfo;
return info.systemVersion ?? 'Unknown';
}
if (Platform.isMacOS) {
final info = await deviceInfo.macOsInfo;
return info.osRelease;
}
if (Platform.isLinux) {
final info = await deviceInfo.linuxInfo;
return info.version ?? 'Unknown';
}
return 'Unknown Version';
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3688 次 |
| 最近记录: |