etch 0.2.2 copy "etch: ^0.2.2" to clipboard
etch: ^0.2.2 copied to clipboard

A simplified, declarative way to use CustomPainter in Flutter

example/lib/main.dart

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const DemoPage());
  }
}

class DemoPage extends StatefulWidget {
  const DemoPage({Key? key}) : super(key: key);

  @override
  _DemoPageState createState() => _DemoPageState();
}

class _DemoPageState extends State<DemoPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: EtchCanvas(
          etchElements: [
            EtchLayer.scale(
              scale: const Offset(1, 2),
              etchElements: [
                EtchLine(
                    start: const Offset(0, 0), end: const Offset(100, 100)),
                EtchLine(
                    start: const Offset(0, 50), end: const Offset(100, 100)),
              ],
            ),
            // EtchLayer(
            //   transform: Matrix4.identity(),
            //   etchElements: [
            //     EtchRect.alignment(
            //       topLeftAlignment: Offset(-1, -1),
            //       bottomRightAlignment: Offset(1, 1),
            //     ),
            //   ],
            // ),
            EtchPath(
              etchPathElements: [
                EtchPathMoveTo(point: Offset(0, 0)),
                EtchPathLine(point: Offset(110, 0)),
                EtchPathLine(point: Offset(110, 110)),
                EtchPathClose(),
              ],
              etchStyle: EtchStyle(
                style: PaintingStyle.stroke,
              ),
            ),
            // EtchRect.alignment(
            //   topLeftAlignment: Offset.zero,
            //   bottomRightAlignment: Offset(1, 1),
            // ),
            // EtchOval.alignment(
            //   topLeftAlignment: Offset(-1, -1),
            //   bottomRightAlignment: Offset(0, 0),
            // ),
            // EtchArc.alignment(
            //   topLeftAlignment: Offset(-1, -1),
            //   bottomRightAlignment: Offset(1, 1),
            //   startAngle: 0,
            //   sweepAngle: 2,
            // ),
            // EtchCircle(
            //   center: Offset(100, 100),
            //   radius: 50.0,
            // ),
            EtchPath(
              etchPathElements: [
                EtchPathMoveTo(point: const Offset(0, 0)),
                EtchPathAddPolygon.alignment(
                  pointAlignments: [
                    const Offset(0, 0),
                    const Offset(1, 0),
                    const Offset(1, 1),
                  ],
                ),
                EtchPathConicTo.alignment(
                  controlPointAlignment: const Offset(0.2, 0.4),
                  endPointAlignment: const Offset(0.5, -0.5),
                ),
                EtchPathClose(),
              ],
              etchStyle: EtchStyle(
                style: PaintingStyle.stroke,
              ),
            ),
          ],
          child: const SizedBox(
            width: 100.0,
            height: 100.0,
          ),
        ),
      ),
    );
  }
}
79
likes
160
points
24
downloads

Publisher

verified publisherjoshi.dev

Weekly Downloads

A simplified, declarative way to use CustomPainter in Flutter

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-2-Clause (license)

Dependencies

flutter

More

Packages that depend on etch