platform.dart 956 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import 'dart:io';
  2. import 'dart:async';
  3. import 'package:device_info/device_info.dart';
  4. import 'package:package_info/package_info.dart';
  5. export 'dart:io';
  6. /// 是否是生产环境
  7. const bool inProduction = const bool.fromEnvironment("dart.vm.product");
  8. class PlatformUtils {
  9. static Future<PackageInfo> getAppPackageInfo() {
  10. return PackageInfo.fromPlatform();
  11. }
  12. static Future<String> getAppVersion() async {
  13. PackageInfo packageInfo = await PackageInfo.fromPlatform();
  14. return packageInfo.version;
  15. }
  16. static Future<String> getBuildNum() async {
  17. PackageInfo packageInfo = await PackageInfo.fromPlatform();
  18. return packageInfo.buildNumber;
  19. }
  20. static Future getDeviceInfo() async {
  21. DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  22. if (Platform.isAndroid) {
  23. return await deviceInfo.androidInfo;
  24. } else if (Platform.isIOS) {
  25. return await deviceInfo.iosInfo;
  26. } else {
  27. return null;
  28. }
  29. }
  30. }