flutter_html_css_percent_size 0.3.0 copy "flutter_html_css_percent_size: ^0.3.0" to clipboard
flutter_html_css_percent_size: ^0.3.0 copied to clipboard

A flutter_html extension that renders percentage width, height, padding and margin, which flutter_html 3.0.0 parses as zero.

example/example.md

Example #

A runnable app. Nesting is the case the README does not show: a percentage resolves against its own parent, so 50% inside 75% is 37.5% of the page.

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

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) => MaterialApp(
        home: Scaffold(
          body: Html(
            data: '''
              <div style="width: 50%">Half the width of the page.</div>

              <div style="width: 75%">
                <div style="width: 50%">37.5% of the page.</div>
              </div>

              <img src="https://example.com/photo.jpg" style="width: 50%">

              <div style="padding: 5%; margin: 0 5%">Padding and margin resolve against the width.</div>
            ''',
            extensions: const [CssPercentSizeHtmlExtension()],
          ),
        ),
      );
}

void main() => runApp(const ExampleApp());

The image keeps its aspect ratio. The pixel width goes into Style.width, the built-in image renderer passes that value to Image.width, and an Image with a width and no height sizes the other axis from the source.

The last block takes 5% of the page width on every side, the vertical ones included, which is what CSS does with a percentage padding or margin.

The README carries the registration order against the companion extensions, the resolvePercentages flag an IntrinsicHeight needs, and what this package does not do. The measured order matrix is in doc/composition.md.

0
likes
160
points
40
downloads

Documentation

API reference

Publisher

verified publisherchaosworld.cc

Weekly Downloads

A flutter_html extension that renders percentage width, height, padding and margin, which flutter_html 3.0.0 parses as zero.

Repository (GitLab)
View/report issues
Contributing

Topics

#flutter-html #css #html #extension #percentage

License

MPL-2.0 (license)

Dependencies

flutter, flutter_html, html

More

Packages that depend on flutter_html_css_percent_size