Search
 
SCRIPT & CODE EXAMPLE
 

DART

heart shape container flutter

class Heart extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: CustomPaint(
        painter: TrianglePainter(
          strokeColor: Color(0xFFF27788),
          paintingStyle: PaintingStyle.fill,
        ),
        child: Container(
          height: 60 * Dep.hr,
          width: 60 * Dep.hr,
        ),
      ),
    );
  }
}

class TrianglePainter extends CustomPainter {
  final Color strokeColor;
  final PaintingStyle paintingStyle;
  final double strokeWidth;

  TrianglePainter({this.strokeColor, this.strokeWidth = 3, this.paintingStyle = PaintingStyle.stroke});

  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint()
      ..color = strokeColor
      ..strokeWidth = strokeWidth
      ..style = paintingStyle;

    canvas.drawPath(getTrianglePath(size.width, size.height), paint);
  }

  Path getTrianglePath(double x, double y) {
    return Path()
      ..moveTo(y, 0)
      ..lineTo(0, 0)
      ..lineTo(x / 2, y);
  }

  @override
  bool shouldRepaint(TrianglePainter oldDelegate) {
    return oldDelegate.strokeColor != strokeColor ||
        oldDelegate.paintingStyle != paintingStyle ||
        oldDelegate.strokeWidth != strokeWidth;
  }
}
Comment

flutter heart shape

class HeartWidget extends StatefulWidget {
    @override
    _HeartWidgetState createState() => _HeartWidgetState();
  }

  class _HeartWidgetState extends State<HeartWidget> {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text('Testing'),
        ),
        body: Center(
        child: CustomPaint(
            size: Size(70, 80),
            painter: HeartPainter(),
          ),
        ),
      );
    }
  }

  class HeartPainter extends CustomPainter {
    @override
    void paint(Canvas canvas, Size size) {
      // TODO: implement paint
      Paint paint = Paint();
      paint
        ..color = Colors.black
        ..style = PaintingStyle.stroke
        ..strokeCap = StrokeCap.round
        ..strokeWidth = 6;

      Paint paint1 = Paint();
      paint1
        ..color = Colors.red
        ..style = PaintingStyle.fill
        ..strokeWidth = 0;

      double width = size.width;
      double height = size.height;

      Path path = Path();
      path.moveTo(0.5 * width, height * 0.35);
      path.cubicTo(0.2 * width, height * 0.1, -0.25 * width, height * 0.6,
          0.5 * width, height);
      path.moveTo(0.5 * width, height * 0.35);
      path.cubicTo(0.8 * width, height * 0.1, 1.25 * width, height * 0.6,
          0.5 * width, height);

      canvas.drawPath(path, paint1);
      canvas.drawPath(path, paint);
    }

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

PREVIOUS NEXT
Code Example
Dart :: Array of colors in dart 
Dart :: text color flutter 
Dart :: AnimatedCrossFade 
Dart :: function in dart 
Dart :: flutter bool variable 
Dart :: increase widh of TableCell in flutter 
Dart :: flutter tabbar 
Dart :: how to check Flutter app comes to foreground 
Dart :: @override in dart 
Dart :: how to vibrate phone flutter 
Dart :: flutter get language code 
Dart :: how to use wrap widget in flutter 
Dart :: search functionality dart 
Dart :: Dart simple program 
Dart :: dart truncate 
Dart :: nullable conditional assignment dart 
Dart :: create array in flutter 
Dart :: flutter compare two list 
Dart :: dart list of lists 
Dart :: string to int in flutter 
Swift :: delay code execution swift 5 
Swift :: Detect if device is ipad or iphone swift 
Swift :: convert string to int swift 
Swift :: How to change the backgroundColor of UIDatePicker or UIPicker ? 
Swift :: swipe left to go back iphone swift 
Swift :: alamofire failure response body 
Swift :: add corner radius to uiview swift 
Swift :: how do change title color in navigation bar 
Swift :: tuple swift 
Swift :: how to change the color of back button navbar xcodee 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =