Sub6Resources / flutter_html

A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
https://pub.dev/packages/flutter_html
MIT License
1.76k stars 815 forks source link

[FEATURE] Support for max-width #1334

Open TheCarpetMerchant opened 11 months ago

TheCarpetMerchant commented 11 months ago

It would be nice to have support for max-width:100%, so that images that have a set width don't get rendered bigger then the screen.

Code I used to test things out :

import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        body: Html(
          data: '<img style="width:800px;max-width:5%" src="https://cdn.discordapp.com/attachments/840351500010258474/968560163382521946/2022-03-31_14-16-27_0503.jpg"/>',
        ),
      ),
    ),
  );
}
Mohamed-Aziz-Mhadhbi commented 11 months ago

You can also add SingleChildScrollView widget to ensure the content can scroll if it exceeds the screen height.

The updated code :

import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        body: SingleChildScrollView(
          child: Html(
            data: '''
              <style>
                img {
                  width: 800px;
                  max-width: 100%;
                }
              </style>
              <img src="https://cdn.discordapp.com/attachments/840351500010258474/968560163382521946/2022-03-31_14-16-27_0503.jpg"/>
            ''',
          ),
        ),
      ),
    ),
  );
}
TheCarpetMerchant commented 11 months ago

@Mohamed-Aziz-Mhadhbi This is an issue about width, not height...

thanhle7 commented 9 months ago

It would be nice to have support for max-width:100%, so that images that have a set width don't get rendered bigger then the screen.

Code I used to test things out :

import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        body: Html(
          data: '<img style="width:800px;max-width:5%" src="https://cdn.discordapp.com/attachments/840351500010258474/968560163382521946/2022-03-31_14-16-27_0503.jpg"/>',
        ),
      ),
    ),
  );
}

I am 2nd for that

TheCarpetMerchant commented 9 months ago

See #1359.