How can I draw shadows along the path I draw?

1,442 views
Skip to first unread message

Aries Lee

unread,
Jul 4, 2019, 1:49:09 AM7/4/19
to Flutter Development (flutter-dev)
I want to add a shadow as shown below!
However, canvas.drawShadow is invalid!
what should I do?

1.png



import 'package:flutter/material.dart';

class NavCustomPainter extends CustomPainter {
    double loc;
    double s;
    Color color;
    TextDirection textDirection;

    NavCustomPainter(double startingLoc, int itemsLength, this.color,
        this.textDirection) {
        final span = 1.0 / itemsLength;
        s = 0.2;
        double l = startingLoc + (span - s) / 2;
        loc = textDirection == TextDirection.rtl ? 0.8 - l : l;
    }

    @override
    void paint(Canvas canvas, Size size) {
        final paint = Paint()
            ..color = color
            ..style = PaintingStyle.fill;

        final path = Path()
            ..moveTo(0, 0)
            ..lineTo((loc - 0.1) * size.width, 0)
            ..cubicTo(
                (loc + s * 0.20) * size.width,
                size.height * 0.05,
                loc * size.width,
                size.height * 0.60,
                (loc + s * 0.50) * size.width,
                size.height * 0.60,
            )..cubicTo(
                (loc + s) * size.width,
                size.height * 0.60,
                (loc + s - s * 0.20) * size.width,
                size.height * 0.05,
                (loc + s + 0.1) * size.width,
                0,
            )
            ..lineTo(size.width, 0)..lineTo(size.width, size.height)..lineTo(
                0, size.height)
            ..close();
        canvas.drawShadow(path, Colors.green, 3.0, true);   // This line does not take effect
        canvas.drawPath(path, paint);
    }

    @override
    bool shouldRepaint(CustomPainter oldDelegate) {
        return this != oldDelegate;
    }
}



Vijay Rathod

unread,
Jun 10, 2020, 3:08:05 PM6/10/20
to Flutter Development (flutter-dev)
Did you find any solution?

Souvik Dutta

unread,
Jun 10, 2020, 10:37:45 PM6/10/20
to Vijay Rathod, Flutter Development (flutter-dev)
Does you elevation property of the bottom nav bar help?

Souvik flutter dev

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/5c75b191-db8e-47ea-b760-acc3ce18dec8o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages