application.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'dart:io';
  4. import 'package:device_info/device_info.dart';
  5. import 'package:fluro/fluro.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:logger/logger.dart';
  8. import 'package:package_info/package_info.dart';
  9. import 'package:permission_handler/permission_handler.dart';
  10. const bool inProduction = const bool.fromEnvironment("dart.vm.product");
  11. final logger = Logger();
  12. final RouteObserver<ModalRoute> routeObserver = RouteObserver<ModalRoute>();
  13. class Application {
  14. static BuildContext? context;
  15. static FluroRouter? router;
  16. static Map<int, bool> gameLikes = {};
  17. static int currentPage = 0;
  18. static Future<String> getDeviceInfo() async {
  19. DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  20. Map<String, dynamic> infos = {};
  21. infos['os'] = Platform.isAndroid
  22. ? 1
  23. : Platform.isIOS
  24. ? 2
  25. : 3;
  26. PackageInfo packageInfo = await PackageInfo.fromPlatform();
  27. infos['versionCode'] = packageInfo.buildNumber;
  28. infos['versionName'] = packageInfo.version;
  29. if (Platform.isIOS) {
  30. print('IOS设备:');
  31. IosDeviceInfo info = await deviceInfo.iosInfo;
  32. infos['name'] = info.name;
  33. infos['model'] = info.model;
  34. infos['identifierForVendor'] = info.identifierForVendor;
  35. infos['isPhysicalDevice'] = info.isPhysicalDevice;
  36. infos['systemName'] = info.systemName;
  37. infos['systemVersion'] = info.systemVersion;
  38. infos['utsname'] = info.utsname;
  39. } else if (Platform.isAndroid) {
  40. print('Android设备');
  41. AndroidDeviceInfo info = await deviceInfo.androidInfo;
  42. infos['model'] = info.model;
  43. infos['isPhysicalDevice'] = info.isPhysicalDevice;
  44. infos['id'] = info.id;
  45. infos['type'] = info.type;
  46. infos['tags'] = info.tags;
  47. infos['device'] = info.device;
  48. infos['androidId'] = info.androidId;
  49. infos['board'] = info.board;
  50. infos['bootloader'] = info.bootloader;
  51. infos['brand'] = info.brand;
  52. infos['display'] = info.display;
  53. infos['fingerprint'] = info.fingerprint;
  54. infos['hardware'] = info.hardware;
  55. infos['manufacturer'] = info.manufacturer;
  56. infos['product'] = info.product;
  57. var version = info.version;
  58. infos['baseOS'] = version.baseOS;
  59. infos['codename'] = version.codename;
  60. infos['sdkInt'] = version.sdkInt;
  61. infos['release'] = version.release;
  62. }
  63. return json.encode(infos);
  64. }
  65. static Future<bool> requestPermission(Permission permission) async {
  66. PermissionStatus _permissionStatus = await permission.status;
  67. if (_permissionStatus != PermissionStatus.granted) {
  68. // 没有权限,发起请求权限
  69. _permissionStatus = await permission.request();
  70. return _permissionStatus == PermissionStatus.granted;
  71. } else {
  72. return true;
  73. }
  74. }
  75. }