Skip to content

Instantly share code, notes, and snippets.

@coman3
Last active January 13, 2025 17:00
Show Gist options
  • Save coman3/e631fd55cd9cdf9bd4efe8ecfdbb85a7 to your computer and use it in GitHub Desktop.
Save coman3/e631fd55cd9cdf9bd4efe8ecfdbb85a7 to your computer and use it in GitHub Desktop.

Revisions

  1. coman3 revised this gist Feb 15, 2023. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion ClipShadowPath.dart
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,6 @@ class ClipShadowPath extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
    return CustomPaint(
    key: UniqueKey(),
    painter: _ClipShadowShadowPainter(
    clipper: this.clipper,
    shadow: this.shadow,
  2. coman3 revised this gist May 27, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ClipShadowPath.dart
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,7 @@ class ClipShadowPath extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
    return CustomPaint(
    key: UniqueKey(),
    painter: _ClipShadowShadowPainter(
    clipper: this.clipper,
    shadow: this.shadow,
  3. coman3 revised this gist Apr 9, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion ClipShadowPath.dart
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,8 @@ class _ClipShadowShadowPainter extends CustomPainter {
    @override
    void paint(Canvas canvas, Size size) {
    var paint = shadow.toPaint();
    canvas.drawPath(clipper.getClip(size), paint);
    var clipPath = clipper.getClip(size).shift(shadow.offset);
    canvas.drawPath(clipPath, paint);
    }

    @override
  4. coman3 revised this gist Jan 27, 2019. 1 changed file with 12 additions and 33 deletions.
    45 changes: 12 additions & 33 deletions ClipShadowPath.dart
    Original file line number Diff line number Diff line change
    @@ -1,60 +1,39 @@
    import 'package:flutter/material.dart';

    typedef Path BuildPath(Size size);

    @immutable
    class ClipShadowPath extends StatelessWidget {
    final Shadow shadow;
    final BuildPath buildPath;
    final CustomClipper<Path> clipper;
    final Widget child;

    ClipShadowPath(
    {@required this.shadow, @required this.buildPath, @required this.child});
    ClipShadowPath({
    @required this.shadow,
    @required this.clipper,
    @required this.child,
    });

    @override
    Widget build(BuildContext context) {
    return CustomPaint(
    painter: _ClipShadowShadowPainter(
    buildPath: this.buildPath, shadow: this.shadow),
    child: ClipPath(
    child: child,
    clipper: _ClipShadowPathClipper(
    buildPath: this.buildPath,
    ),
    clipper: this.clipper,
    shadow: this.shadow,
    ),
    child: ClipPath(child: child, clipper: this.clipper),
    );
    }
    }

    class _ClipShadowPathClipper extends CustomClipper<Path> {
    final BuildPath buildPath;
    _ClipShadowPathClipper({
    @required this.buildPath,
    });
    @override
    Path getClip(Size size) {
    return this.buildPath(size);
    }

    @override
    bool shouldReclip(CustomClipper<Path> oldClipper) {
    return true;
    }
    }

    class _ClipShadowShadowPainter extends CustomPainter {
    final BuildPath buildPath;
    final Shadow shadow;
    final CustomClipper<Path> clipper;

    _ClipShadowShadowPainter({
    @required this.buildPath,
    @required this.shadow,
    });
    _ClipShadowShadowPainter({@required this.shadow, @required this.clipper});

    @override
    void paint(Canvas canvas, Size size) {
    var paint = shadow.toPaint();
    canvas.drawPath(this.buildPath(size), paint);
    canvas.drawPath(clipper.getClip(size), paint);
    }

    @override
  5. coman3 created this gist Jan 27, 2019.
    64 changes: 64 additions & 0 deletions ClipShadowPath.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    import 'package:flutter/material.dart';

    typedef Path BuildPath(Size size);

    @immutable
    class ClipShadowPath extends StatelessWidget {
    final Shadow shadow;
    final BuildPath buildPath;
    final Widget child;

    ClipShadowPath(
    {@required this.shadow, @required this.buildPath, @required this.child});

    @override
    Widget build(BuildContext context) {
    return CustomPaint(
    painter: _ClipShadowShadowPainter(
    buildPath: this.buildPath, shadow: this.shadow),
    child: ClipPath(
    child: child,
    clipper: _ClipShadowPathClipper(
    buildPath: this.buildPath,
    ),
    ),
    );
    }
    }

    class _ClipShadowPathClipper extends CustomClipper<Path> {
    final BuildPath buildPath;
    _ClipShadowPathClipper({
    @required this.buildPath,
    });
    @override
    Path getClip(Size size) {
    return this.buildPath(size);
    }

    @override
    bool shouldReclip(CustomClipper<Path> oldClipper) {
    return true;
    }
    }

    class _ClipShadowShadowPainter extends CustomPainter {
    final BuildPath buildPath;
    final Shadow shadow;

    _ClipShadowShadowPainter({
    @required this.buildPath,
    @required this.shadow,
    });

    @override
    void paint(Canvas canvas, Size size) {
    var paint = shadow.toPaint();
    canvas.drawPath(this.buildPath(size), paint);
    }

    @override
    bool shouldRepaint(CustomPainter oldDelegate) {
    return true;
    }
    }