flutter_html icon indicating copy to clipboard operation
flutter_html copied to clipboard

max-width attribute and auto-margins on network images for Flutter 3.10

Open TheCarpetMerchant opened this issue 2 years ago • 7 comments

This PR is not ready to be merged. I made it as best as I could while trying to learn the inner workings of this beautiful package :)

  • max-width is applied only within the build function of CssBoxWidget ; I have no idea if this is complete or even correct.
  • The behavior isn't fully coded
  • I added shrinkWrap to network images so they could work with Flutter 3.10, which apparently is the cause of images going out of screen (#1357)

Hopefully, it's not too shabby. The use of shrinkWrap should probably be removed in favor of understanding what's going wrong in the _calculateUsedMargins, but I haven't even tried given shrinkWrap fixes it (by bypassing the issue), at least AFAIK.

TheCarpetMerchant avatar Aug 15 '23 18:08 TheCarpetMerchant

image

  1. It is necessary to determine whether the current style width is greater than the screen width;
  2. Keep the aspect ratio of the picture, otherwise the picture will be stretched and distorted image Where used set like this.

Rockets1080 avatar Aug 23 '23 06:08 Rockets1080

This PR is not ready to be merged. I made it as best as I could while trying to learn the inner workings of this beautiful package :)

@TheCarpetMerchant Do you intend to finish it or would you prefer someone to take over?

eEQK avatar Sep 01 '23 08:09 eEQK

@eEQK Would prefer someone at least look it over. I didn't even run tests because my local setup kept erroring out ; it just works for my use case as is. If what I did is enough then great, but it would still be better someone take it over, especially to separate the 2 commits which are really two different things.

TheCarpetMerchant avatar Sep 01 '23 09:09 TheCarpetMerchant

@eEQK Finally back to it. What's missing for now it the ability to compare 2 Widths that aren't in the same unit, if you know how to do that on a sufficient "best effort" basis at least that'd be great. Since there's now a bunch of commits and this is 2 separate things in one PR (maxWidth and the BoxFit.contain change), I can close this PR and open 2 others if you think it's better for the commit history.

TheCarpetMerchant avatar Oct 03 '23 16:10 TheCarpetMerchant

Adding fit: BoxFit.contain, to lib/src/builtins/image_builtin.dart

and using the width property in HTML() as follows: 'img': Style( width: Width( MediaQuery.of(context).size.width, Unit.auto, ), )

This give image width a good size but shows empty white space above and below the image. Something that can be recommended?

utkarshmarwaha avatar Jul 14 '24 11:07 utkarshmarwaha

'img': Style( width: Width( MediaQuery.of(context).size.width, Unit.auto, ), )

Any update on this issue?

 Html(
                  shrinkWrap: true,
                  data: widget.content,
                  onLinkTap: (url, _, __) {
                    handleLinkTap(url, _, __, _);
                  },
                  style: {
                    "body": Style(
                      margin: Margins.zero,
                      padding: HtmlPaddings.symmetric(horizontal: 0),
                    ),
                    'img': Style(
                      width: Width(100, Unit.px),
                    )
                  }),

unable to render image

pranavo72bex avatar Jul 23 '24 05:07 pranavo72bex