updateMetadata method
Function to update the data in MBurger.
Implementation
Future<void> updateMetadata() async {
var defaultParameters = await MBManager.shared.defaultParameters();
var headers = await MBManager.shared.headers(contentTypeJson: true);
Map<String, dynamic> parameters = <String, dynamic>{};
parameters.addAll(defaultParameters);
if (Platform.isIOS) {
PermissionStatus pushPermission = await Permission.notification.status;
parameters['push_enabled'] =
pushPermission == PermissionStatus.granted ? 1 : 0;
} else {
parameters['push_enabled'] = 1;
}
PermissionStatus locationPermission = await Permission.location.status;
parameters['location_enabled'] =
locationPermission == PermissionStatus.granted ? 1 : 0;
parameters['locale'] = Platform.localeName;
PackageInfo packageInfo = await PackageInfo.fromPlatform();
if (Platform.isIOS) {
parameters['app_version'] = packageInfo.version;
} else {
parameters['app_version'] = packageInfo.buildNumber;
}
parameters['sessions'] = await _sessionManager.currentSession;
parameters['sessions_time'] = await _sessionManager.totalSessionTime;
int currentSession = await _sessionManager.currentSession;
DateTime? dateTime =
await _sessionManager.startSessionDateForSession(currentSession);
if (dateTime != null) {
parameters['last_session'] = dateTime.millisecondsSinceEpoch ~/ 1000.0;
} else {
parameters['last_session'] = 0;
}
int? mobileUserId = await _idsManager.getMobileUserId();
if (mobileUserId != null) {
parameters['mobile_user_id'] = mobileUserId;
}
String? customId = await _idsManager.getCustomId();
if (customId != null) {
parameters['custom_id'] = customId;
}
if (_currentLocation != null) {
parameters['latitude'] = _currentLocation!.latitude;
parameters['longitude'] = _currentLocation!.longitude;
}
List<Map<String, String>>? savedTags =
await _tagsManager.getTagsAsDictionaries();
if (savedTags != null) {
parameters['tags'] = savedTags;
}
if (Platform.isIOS) {
parameters['platform'] = 'ios';
} else if (Platform.isAndroid) {
parameters['platform'] = 'android';
}
var uri = Uri.https(MBManager.shared.endpoint, 'api/devices');
var response = await http.post(
uri,
headers: headers,
body: json.encode(parameters),
);
MBManager.checkResponse(response.body, checkBody: false);
}