I'm using Crashlytics in my Flutter app through firebase_crashlytics package.
I read that I can use custom key to send additional data with setCustomKey method. However, I couldn't find a way to remove it for the next error report.
Here is my firebase_logger.dart
class FirebaseLogger implements ILogger {
FirebaseCrashlytics get _crashlytics => FirebaseCrashlytics.instance;
@override
Future<void> init() async {
await Firebase.initializeApp();
}
@override
Future<void> trackError(
String name, {
Map<String, String> properties,
dynamic exception,
StackTrace stackTrace,
}) async {
final String userId = getUserId();
if (userId != null) _crashlytics.setUserIdentifier(userId);
properties.forEach((key, value) {
_crashlytics.setCustomKey(key, value);
});
_crashlytics.recordError(exception, stackTrace);
// Clear the keys for the next log
properties.forEach((key, value) {
_crashlytics.setCustomKey(key, '');
});
if (employeeId != null) _crashlytics.setUserIdentifier('');
}
}
and here are my error methods:
Future<void> testError1() async {
try {
throw Exception('error 1');
} catch (e, s) {
await _logger.trackError(
'testError1',
properties: {'name1': 'name 1', 'id1': 'id 1'},
exception: e,
stackTrace: s,
);
}
}
Future<void> testError2() async {
try {
throw Exception('error 2');
} catch (e, s) {
await _logger.trackError(
'testError2',
properties: {'name2': 'name 2', 'id2': 'id 2'},
exception: e,
stackTrace: s,
);
}
}
I tried triggering testError1 and then testError2.
I read old questions (which may not valid anymore) that I had to set it null or empty in android SDK, but in flutter they checked it with assert not null. Giving them empty value gave the result of testError2 empty id1 and name1 properties. Is there a way to reset the keys/properties?