flutter_html_css_object_fit 0.2.0 copy "flutter_html_css_object_fit: ^0.2.0" to clipboard
flutter_html_css_object_fit: ^0.2.0 copied to clipboard

A flutter_html extension that renders the CSS object-fit and object-position properties on images.

example/example.md

Example #

flutter_html 3.0.0 hardcodes BoxFit.fill in all three of its image renderers. No parameter and no Style field reaches it. A photo in a box of another shape therefore renders stretched. This extension renders object-fit and object-position from the <img> element's inline style.

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

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

  @override
  Widget build(BuildContext context) => MaterialApp(
        home: Scaffold(
          body: Html(
            data: '''
              <!-- both a width and a height, or there is no box to fit -->
              <img src="https://example.com/photo.jpg"
                   width="240" height="80"
                   style="object-fit: cover;">

              <img src="https://example.com/photo.jpg"
                   width="240" height="80"
                   style="object-fit: contain;">

              <img src="https://example.com/photo.jpg"
                   width="240" height="80"
                   style="object-fit: cover; object-position: 50% 20%;">
            ''',
            extensions: const [CssObjectFitHtmlExtension()],
          ),
        ),
      );
}

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

The first image crops the photo to a wide strip. The second fits the whole photo inside the strip. The third crops it again, and takes the strip from nearer the top of the photo instead of from its middle.

0
likes
160
points
39
downloads

Documentation

API reference

Publisher

verified publisherchaosworld.cc

Weekly Downloads

A flutter_html extension that renders the CSS object-fit and object-position properties on images.

Repository (GitLab)
View/report issues
Contributing

Topics

#flutter-html #css #html #extension #object-fit

License

MPL-2.0 (license)

Dependencies

flutter, flutter_html, html

More

Packages that depend on flutter_html_css_object_fit