86 lines
2.5 KiB
Dart
86 lines
2.5 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:device_info/device_info.dart';
|
|
import 'package:geolocator/geolocator.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
Future<String> getDeviceId() async {
|
|
String deviceId = "";
|
|
final DeviceInfoPlugin deviceInfoPlugin = new DeviceInfoPlugin();
|
|
try {
|
|
if (Platform.isAndroid) {
|
|
var build = await deviceInfoPlugin.androidInfo;
|
|
String version = build.version.release;
|
|
deviceId = version; // Android
|
|
} else if (Platform.isIOS) {
|
|
var data = await deviceInfoPlugin.iosInfo;
|
|
String version = data.systemVersion;
|
|
deviceId = version; // iOS
|
|
}
|
|
} catch (e) {
|
|
print('Failed to get device id: $e');
|
|
}
|
|
return deviceId;
|
|
}
|
|
|
|
Future<String> getImei() async {
|
|
String imei = "";
|
|
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
|
if (Platform.isAndroid) {
|
|
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
|
imei = androidInfo.androidId;
|
|
// other specific Android data
|
|
} else if (Platform.isIOS) {
|
|
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
|
|
imei = iosInfo.identifierForVendor;
|
|
// other specific iOS data
|
|
}
|
|
return imei;
|
|
}
|
|
|
|
Future<String> getBrand() async {
|
|
String brand = '';
|
|
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
|
if (Platform.isIOS) {
|
|
IosDeviceInfo iosDeviceInfo = await deviceInfo.iosInfo;
|
|
brand = iosDeviceInfo.model;
|
|
} else if (Platform.isAndroid) {
|
|
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
|
brand = androidInfo.model;
|
|
}
|
|
return brand;
|
|
}
|
|
|
|
Future<LatLng> getLocation() async {
|
|
LatLng latLng = LatLng(latitude: 0.0, longitude: 0.0);;
|
|
try {
|
|
LocationPermission permission = await Geolocator.requestPermission();
|
|
if (permission == LocationPermission.whileInUse ||
|
|
permission == LocationPermission.always) {
|
|
Position position = await Geolocator.getCurrentPosition(
|
|
desiredAccuracy: LocationAccuracy.high,
|
|
);
|
|
print('Latitude: ${position.latitude}');
|
|
print('Longitude: ${position.longitude}');
|
|
latLng= LatLng(latitude: position.latitude, longitude: position.longitude);
|
|
} else {
|
|
print('Location permission denied');
|
|
}
|
|
} catch (e) {
|
|
print('Failed to get device or location info: $e');
|
|
}
|
|
return latLng;
|
|
}
|
|
|
|
class LatLng {
|
|
final double latitude;
|
|
final double longitude;
|
|
|
|
LatLng({required this.latitude, required this.longitude});
|
|
}
|
|
|
|
Future<String> getAuthorization() async {
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
return prefs.getString("Authorization") ?? "";
|
|
}
|