import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:device_info/device_info.dart'; import 'package:fluro/fluro.dart'; import 'package:flutter/material.dart'; import 'package:logger/logger.dart'; import 'package:package_info/package_info.dart'; import 'package:permission_handler/permission_handler.dart'; const bool inProduction = const bool.fromEnvironment("dart.vm.product"); bool isDebugShoe = false; String shoeVersion = ""; bool openSocial() { // return false; return isDebugShoe || Platform.isIOS; } final logger = Logger(); final RouteObserver routeObserver = RouteObserver(); Locale? locale; double weight = 60.0; int gender = 0; String? buyShoesUrl; AppLifecycleState? appLifecycleState = AppLifecycleState.resumed; ConnectivityResult? connectivityResult; class Application { static BuildContext? context; static FluroRouter? router; static Map gameLikes = {}; static int currentPage = 0; static Map infos = {}; static Future getDeviceInfo() async { Map infos = await getDeviceInfoMap(); return json.encode(infos); } static Future> getDeviceInfoMap() async { if (infos.isNotEmpty) return infos; infos['os'] = Platform.isAndroid ? 1 : Platform.isIOS ? 2 : 3; PackageInfo packageInfo = await PackageInfo.fromPlatform(); infos['versionCode'] = packageInfo.buildNumber; infos['versionName'] = packageInfo.version; infos['locale'] = locale?.languageCode ?? ""; try { DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); if (Platform.isIOS) { print('IOS设备:'); IosDeviceInfo info = await deviceInfo.iosInfo; infos['brand'] = info.model; infos['name'] = info.name; infos['model'] = info.utsname.machine; infos['identifierForVendor'] = info.identifierForVendor; infos['isPhysicalDevice'] = info.isPhysicalDevice; infos['systemName'] = info.systemName; infos['systemVersion'] = info.systemVersion; infos['utsname'] = info.utsname.sysname + "_" + info.utsname.nodename + "_" + info.utsname.machine + "_" + info.utsname.version + "_" + info.utsname.release; } else if (Platform.isAndroid) { print('Android设备'); AndroidDeviceInfo info = await deviceInfo.androidInfo; infos['model'] = info.model; infos['isPhysicalDevice'] = info.isPhysicalDevice; //infos['id'] = info.id; //infos['type'] = info.type; // infos['tags'] = info.tags; infos['device'] = info.device; infos['androidId'] = info.androidId; infos['board'] = info.board; //infos['bootloader'] = info.bootloader; infos['brand'] = info.brand; //infos['display'] = info.display; //infos['fingerprint'] = info.fingerprint; infos['hardware'] = info.hardware; infos['manufacturer'] = info.manufacturer; infos['product'] = info.product; var version = info.version; infos['baseOS'] = version.baseOS; infos['codename'] = version.codename; infos['sdkInt'] = version.sdkInt; infos['release'] = version.release; } } catch (e) { print(e); } infos.forEach((key, value) { if(value is String) infos[key] = Uri.encodeComponent(value); }); return infos; } static Future requestPermission(Permission permission) async { PermissionStatus _permissionStatus = await permission.status; if (_permissionStatus != PermissionStatus.granted) { // 没有权限,发起请求权限 _permissionStatus = await permission.request(); return _permissionStatus == PermissionStatus.granted; } else { return true; } } }