flutter_html icon indicating copy to clipboard operation
flutter_html copied to clipboard

[FEATURE] Support for max-width

Open TheCarpetMerchant opened this issue 2 years ago • 4 comments

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"/>',
        ),
      ),
    ),
  );
}

TheCarpetMerchant avatar Jul 01 '23 09:07 TheCarpetMerchant

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"/>
            ''',
          ),
        ),
      ),
    ),
  );
}

Mohamed-Aziz-Mhadhbi avatar Jul 01 '23 10:07 Mohamed-Aziz-Mhadhbi

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

TheCarpetMerchant avatar Jul 04 '23 12:07 TheCarpetMerchant

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

thanhle7 avatar Aug 26 '23 19:08 thanhle7

See #1359.

TheCarpetMerchant avatar Aug 27 '23 08:08 TheCarpetMerchant