Paragraph.fromJson constructor
Paragraph.fromJson(
- Map<String, dynamic> json
)
Implementation
factory Paragraph.fromJson(Map<String, dynamic> json) {
if (json == null) return new Paragraph();
TextAlign textAlign = TextAlign.right;
try {
String textAlignString = json['textAlign'];
textAlign = textAlignString == 'left'
? TextAlign.left
: textAlignString == 'center'
? TextAlign.center
: TextAlign.right;
} catch (exception) {/* ignore */}
String type = json["type"];
String rawContent = json["rawContent"];
String fontFamily = json["fontFamily"];
List<TextSpan> textSpans = [];
try {
if (type == "heading") {
textSpans = parseHeadingHTML(rawContent,
textAlign: textAlign, fontFamily: fontFamily)
.textSpans;
} else if (type == "text") {
textSpans = parseParagraphHTML(rawContent,
textAlign: textAlign, fontFamily: fontFamily)
.textSpans;
} else if (type == "image") {
textSpans = parseFigureCaptionHTML(rawContent);
}
} catch (exception) {/* ignore */}
return Paragraph(
type: json["type"],
rawContent: rawContent,
textSpans: textSpans,
imageUri: json["imageUri"],
youtubeVideoId: json["youtubeVideoId"],
soundcloudTrackId: json["soundcloudTrackId"],
soudcloudEmbedCode: json["soudcloudEmbedCode"],
hearthisAtTrackId: json["hearthisAtTrackId"],
fontFamily: fontFamily,
textAlign: textAlign);
}