application.dart 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'dart:io';
  4. import 'package:amap_core_fluttify/amap_core_fluttify.dart';
  5. import 'package:amap_location_fluttify/amap_location_fluttify.dart';
  6. import 'package:device_info/device_info.dart';
  7. import 'package:fluro/fluro.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:logger/logger.dart';
  10. import 'package:package_info/package_info.dart';
  11. import 'package:permission_handler/permission_handler.dart';
  12. final logger = Logger();
  13. final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
  14. class Application {
  15. static Router 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 ? 1 : Platform.isIOS ? 2 : 3;
  22. PackageInfo packageInfo = await PackageInfo.fromPlatform();
  23. infos['versionCode'] = packageInfo.buildNumber;
  24. infos['versionName'] = packageInfo.version;
  25. if (Platform.isIOS) {
  26. print('IOS设备:');
  27. IosDeviceInfo info = await deviceInfo.iosInfo;
  28. infos['name'] = info.name;
  29. infos['model'] = info.model;
  30. infos['identifierForVendor'] = info.identifierForVendor;
  31. infos['isPhysicalDevice'] = info.isPhysicalDevice;
  32. infos['systemName'] = info.systemName;
  33. infos['systemVersion'] = info.systemVersion;
  34. infos['utsname'] = info.utsname;
  35. } else if (Platform.isAndroid) {
  36. print('Android设备');
  37. AndroidDeviceInfo info = await deviceInfo.androidInfo;
  38. infos['model'] = info.model;
  39. infos['isPhysicalDevice'] = info.isPhysicalDevice;
  40. infos['id'] = info.id;
  41. infos['type'] = info.type;
  42. infos['tags'] = info.tags;
  43. infos['device'] = info.device;
  44. infos['androidId'] = info.androidId;
  45. infos['board'] = info.board;
  46. infos['bootloader'] = info.bootloader;
  47. infos['brand'] = info.brand;
  48. infos['display'] = info.display;
  49. infos['fingerprint'] = info.fingerprint;
  50. infos['hardware'] = info.hardware;
  51. infos['manufacturer'] = info.manufacturer;
  52. infos['product'] = info.product;
  53. var version = info.version;
  54. infos['baseOS'] = version.baseOS;
  55. infos['codename'] = version.codename;
  56. infos['sdkInt'] = version.sdkInt;
  57. infos['release'] = version.release;
  58. }
  59. return json.encode(infos);
  60. }
  61. static Future<Location> location() async {
  62. if (Platform.isIOS) {
  63. await AmapCore.init('4a8518eb97acf5d1998385907e24696a');
  64. }
  65. if (await requestPermission(Permission.location)) {
  66. return await AmapLocation.instance.fetchLocation().catchError((e) {
  67. logger.e(e);
  68. });
  69. }
  70. return null;
  71. }
  72. static Future<bool> requestPermission(Permission permission) async {
  73. if (Platform.isAndroid) {
  74. // 检查当前权限状态。
  75. PermissionStatus _permissionStatus = await permission.status;
  76. if (_permissionStatus != PermissionStatus.granted) {
  77. // 没有权限,发起请求权限
  78. _permissionStatus = await permission.request();
  79. return _permissionStatus == PermissionStatus.granted;
  80. } else {
  81. return true;
  82. }
  83. } else {
  84. return true;
  85. }
  86. }
  87. }