diff --git a/lib/image_properties.dart b/lib/image_properties.dart index 62dfab5b63..2daef94533 100644 --- a/lib/image_properties.dart +++ b/lib/image_properties.dart @@ -4,6 +4,8 @@ import 'package:flutter/material.dart'; class ImageProperties { final String semanticLabel; final bool excludeFromSemantics; + final bool useWidthAttribute; + final bool useHeightAttribute; final double width; final double height; final Color color; @@ -20,6 +22,8 @@ class ImageProperties { this.scale = 1, this.semanticLabel, this.excludeFromSemantics = false, + this.useWidthAttribute = true, + this.useHeightAttribute = true, this.width, this.height, this.color, diff --git a/lib/rich_text_parser.dart b/lib/rich_text_parser.dart index e842b808fd..5da7c1fbd1 100644 --- a/lib/rich_text_parser.dart +++ b/lib/rich_text_parser.dart @@ -739,12 +739,16 @@ class HtmlRichTextParser extends StatelessWidget { if (showImages) { if (node.attributes['src'] != null) { final width = imageProperties?.width ?? - ((node.attributes['width'] != null) - ? double.tryParse(node.attributes['width']) + (imageProperties?.useWidthAttribute ?? true + ? (node.attributes['width'] != null) + ? double.tryParse(node.attributes['width']) + : null : null); final height = imageProperties?.height ?? - ((node.attributes['height'] != null) - ? double.tryParse(node.attributes['height']) + (imageProperties?.useHeightAttribute ?? true + ? (node.attributes['height'] != null) + ? double.tryParse(node.attributes['height']) + : null : null); if (node.attributes['src'].startsWith("data:image") && @@ -788,7 +792,8 @@ class HtmlRichTextParser extends StatelessWidget { }, )); } else if (node.attributes['src'].startsWith('asset:')) { - final assetPath = node.attributes['src'].replaceFirst('asset:', ''); + final assetPath = + node.attributes['src'].replaceFirst('asset:', ''); precacheImage( AssetImage(assetPath), buildContext,