final borderRadius = BorderRadius.circular(16.0); final rect = Rect.fromLTWH(0, 0, size.width, size.height); final roundedRect = RRect.fromRectAndCorners( rect, topLeft: borderRadius.topLeft, topRight: borderRadius.topRight, bottomLeft: borderRadius.bottomLeft, bottomRight: borderRadius.bottomRight, ); final path = Path()..addRRect(roundedRect); canvas.clipPath(path); canvas.saveLayer(rect, paint); canvas.drawPath(path, paint); canvas.restore();