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

A flutter_html extension that renders the CSS transform and transform-origin properties, percentages included.

example/example.md

Example #

flutter_html 3.0.0 maps 51 CSS properties onto a Style and drops the rest. transform and transform-origin are two of the dropped ones. A tilted card therefore renders square, and a scaled badge renders at its normal size. This extension renders both from the element's inline style.

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

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

  @override
  Widget build(BuildContext context) => MaterialApp(
        home: Scaffold(
          body: Html(
            data: '''
              <div style="transform: rotate(-4deg); background-color: #ffe08a;
                          padding: 12px; margin: 8px;">
                A note pinned at an angle.
              </div>

              <div style="transform: scale(1.2); transform-origin: left center;
                          background-color: #cfe2ff; padding: 12px; margin: 8px;">
                Grown from its left edge.
              </div>

              <div style="transform: translate(-50%, -50%) rotate(45deg);
                          background-color: #d1e7dd; padding: 12px; margin: 8px;">
                Pulled back by half its own size, then turned.
              </div>
            ''',
            extensions: const [CssTransformHtmlExtension()],
          ),
        ),
      );
}

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

Without an Html widget #

CssTransformBox takes a whole CSS transform and applies it to any widget. parseCssTransform reads the declaration out of an inline style string. The box resolves a percentage against its own laid-out size during paint, so the functions may come in any order. Layout is untouched, and the child keeps its untransformed box.

import 'package:flutter/widgets.dart';
import 'package:flutter_html_css_transform/flutter_html_css_transform.dart';

Widget pinAtAnAngle(Widget child) => CssTransformBox(
      transform: parseCssTransform(
        'transform: translate(-50%, -50%) rotate(45deg);',
      ),
      child: child,
    );
0
likes
160
points
48
downloads

Documentation

API reference

Publisher

verified publisherchaosworld.cc

Weekly Downloads

A flutter_html extension that renders the CSS transform and transform-origin properties, percentages included.

Repository (GitLab)
View/report issues
Contributing

Topics

#flutter-html #css #html #extension #transform

License

MPL-2.0 (license)

Dependencies

flutter, flutter_html, html

More

Packages that depend on flutter_html_css_transform