DictionaryModel.fromJson constructor
Creates a DictionaryModel from a JSON map.
Example:
final dictionary = DictionaryModel.fromJson({
'word': 'flutter',
'phonetic': '/ˈflʌtər/',
'phonetics': [...],
'meanings': [...],
});
Implementation
factory DictionaryModel.fromJson(Map<String, dynamic> json) {
return DictionaryModel(
word: json['word'] as String? ?? '',
phonetic: json['phonetic'] as String?,
phonetics: (json['phonetics'] as List<dynamic>?)
?.map((e) => PhoneticModel.fromJson(e as Map<String, dynamic>))
.toList() ??
const [],
meanings: (json['meanings'] as List<dynamic>?)
?.map((e) => MeaningModel.fromJson(e as Map<String, dynamic>))
.toList() ??
const [],
license: json['license'] != null
? LicenseModel.fromJson(json['license'] as Map<String, dynamic>)
: null,
sourceUrls: (json['sourceUrls'] as List<dynamic>?)
?.map((e) => e as String)
.toList() ??
const [],
);
}