Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding ability to disable using width and height attributes in img tag #235

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/image_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
15 changes: 10 additions & 5 deletions lib/rich_text_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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") &&
Expand Down Expand Up @@ -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,
Expand Down