init method
Implementation
Future<void> init() async {
if (kIsWeb) {
//web 不支持
String data = DateTime.now().millisecondsSinceEpoch.toString();
data += Random().nextInt(10000).toString();
data = Md5Util.generateMd5(data);
SpUtil.putString(_imei, data);
os = 'web';
return;
}
final PackageInfo info = await PackageUtils.instance.getPackageInfo();
version = info.version;
boundId = info.packageName;
versionCode = '${info.buildNumber}';
final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
if (Platform.isIOS) {
final IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
deviceName = Uri.encodeComponent(iosInfo.name);
os = 'iOS';
osVersion = '${double.tryParse(iosInfo.systemVersion)?.toInt() ?? '0'}';
systemVersion = iosInfo.systemName;
osVersion = iosInfo.systemVersion;
deviceName = iosInfo.name;
} else if (Platform.isAndroid) {
final AndroidDeviceInfo androidDeviceInfo = await deviceInfo.androidInfo;
deviceName =
Uri.encodeComponent('${androidDeviceInfo.brand}${androidDeviceInfo.model} ${androidDeviceInfo.device}');
os = 'Android';
osVersion = '${androidDeviceInfo.version.sdkInt}';
systemVersion = androidDeviceInfo.version.release;
deviceName = androidDeviceInfo.model;
deviceType = androidDeviceInfo.brand;
} else if (Platform.isMacOS) {
final MacOsDeviceInfo macOsInfo = await deviceInfo.macOsInfo;
deviceName = Uri.encodeComponent(macOsInfo.computerName);
os = 'MACOS';
osVersion = macOsInfo.osRelease;
systemVersion = macOsInfo.kernelVersion;
}
final imei = await _getImei(deviceInfo);
imeiId = imei;
debugPrint(toString());
}