import 'dart:io'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:shared_preferences/shared_preferences.dart'; class Globals { static final Globals _singleton = Globals._internal(); factory Globals() { return _singleton; } Globals._internal(); bool _initialized = false; String appName = ''; String packageName = ''; String version = ''; String buildNumber = ''; String platform = ''; String hostname = ''; String clientType = ''; String deviceModel = ''; late SharedPreferences sharedPrefs; bool get isInitialized => _initialized; Future init() async { if (_initialized) return; PackageInfo packageInfo = await PackageInfo.fromPlatform(); this.appName = packageInfo.appName; this.packageName = packageInfo.packageName; this.version = packageInfo.version; this.buildNumber = packageInfo.buildNumber; this.platform = Platform.operatingSystem; this.hostname = Platform.localHostname; if (Platform.isAndroid) { this.clientType = 'ANDROID'; this.deviceModel = (await DeviceInfoPlugin().androidInfo).model; } else if (Platform.isIOS) { this.clientType = 'IOS'; this.deviceModel = (await DeviceInfoPlugin().iosInfo).model; } else if (Platform.isLinux) { this.clientType = 'LINUX'; this.deviceModel = (await DeviceInfoPlugin().linuxInfo).prettyName; } else if (Platform.isWindows) { this.clientType = 'WINDOWS'; this.deviceModel = (await DeviceInfoPlugin().windowsInfo).productName; } else if (Platform.isMacOS) { this.clientType = 'MACOS'; this.deviceModel = (await DeviceInfoPlugin().macOsInfo).model; } else { this.clientType = '?'; } this.sharedPrefs = await SharedPreferences.getInstance(); this._initialized = true; } String? getPrefFCMToken() { return sharedPrefs.getString("fcm.token"); } Future setPrefFCMToken(String value) { return sharedPrefs.setString("fcm.token", value); } }