createNotificationFromJsonData method
As the method channel does: string entries holding JSON are decoded, extra top-level keys are kept, and any failure answers false.
Implementation
@override
Future<bool> createNotificationFromJsonData(
Map<String, dynamic> mapData) async {
try {
final normalized = Map<String, dynamic>.from(mapData);
for (final key in normalized.keys.toList()) {
final value = normalized[key];
if (value is! String) continue;
try {
final decoded = json.decode(value);
if (decoded is Map || decoded is List) normalized[key] = decoded;
} catch (_) {
// Not JSON: keep the string.
}
}
final model = NotificationModel().fromMap(normalized);
if (model == null) throw Exception('Notification map data is invalid');
final data = model.toMap();
for (final entry in normalized.entries) {
data.putIfAbsent(entry.key, () => entry.value);
}
return await _build(data) ?? await engine.present(data);
} catch (_) {
return false;
}
}