device_utils.dart 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import 'dart:io';
  2. import 'package:device_info_plus/device_info_plus.dart';
  3. import 'package:flutter/foundation.dart';
  4. import 'package:ftrecruiter/comm/constants/app_constant.dart';
  5. /// https://medium.com/gskinner-team/flutter-simplify-platform-screen-size-detection-4cb6fc4f7ed1
  6. class Device {
  7. static bool get isDesktop => !isWeb && (isWindows || isLinux || isMacOS);
  8. static bool get isMobile => isAndroid || isIOS;
  9. static bool get isWeb => kIsWeb;
  10. static bool get isWindows => !isWeb && Platform.isWindows;
  11. static bool get isLinux => !isWeb && Platform.isLinux;
  12. static bool get isMacOS => !isWeb && Platform.isMacOS;
  13. static bool get isAndroid => !isWeb && Platform.isAndroid;
  14. static bool get isFuchsia => !isWeb && Platform.isFuchsia;
  15. static bool get isIOS => !isWeb && Platform.isIOS;
  16. static late AndroidDeviceInfo _androidInfo;
  17. static Future<void> initDeviceInfo() async {
  18. if (isAndroid) {
  19. final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  20. _androidInfo = await deviceInfo.androidInfo;
  21. }
  22. }
  23. /// 使用前记得初始化
  24. static int getAndroidSdkInt() {
  25. if (AppConstant.isDriverTest) {
  26. return -1;
  27. }
  28. if (isAndroid) {
  29. return _androidInfo.version.sdkInt ?? -1;
  30. } else {
  31. return -1;
  32. }
  33. }
  34. }