123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- 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<ModalRoute> routeObserver = RouteObserver<ModalRoute>();
- 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<int, bool> gameLikes = {};
- static int currentPage = 0;
- static Map<String, dynamic> infos = {};
- static Future<String> getDeviceInfo() async {
- Map<String, dynamic> infos = await getDeviceInfoMap();
- return json.encode(infos);
- }
- static Future<Map<String, dynamic>> 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);
- }
- return infos;
- }
- static Future<bool> requestPermission(Permission permission) async {
- PermissionStatus _permissionStatus = await permission.status;
- if (_permissionStatus != PermissionStatus.granted) {
- // 没有权限,发起请求权限
- _permissionStatus = await permission.request();
- return _permissionStatus == PermissionStatus.granted;
- } else {
- return true;
- }
- }
- }
|