Flutter Circle Design

后端 未结 5 2101
旧巷少年郎
旧巷少年郎 2021-01-31 02:20

I want to make this kind of design with these white circles as a raised button.

5条回答
  •  不要未来只要你来
    2021-01-31 03:05

    More efficient way

    I suggest you to draw a circle with CustomPainter. It's very easy and way more efficient than creating a bunch of widgets/masks:

    /// Draws a circle if placed into a square widget.
    class CirclePainter extends CustomPainter {
      final _paint = Paint()
        ..color = Colors.red
        ..strokeWidth = 2
        // Use [PaintingStyle.fill] if you want the circle to be filled.
        ..style = PaintingStyle.stroke;
    
      @override
      void paint(Canvas canvas, Size size) {
        canvas.drawOval(
          Rect.fromLTWH(0, 0, size.width, size.height),
          _paint,
        );
      }
    
      @override
      bool shouldRepaint(CustomPainter oldDelegate) => false;
    }
    

    Usage:

      Widget _buildCircle(BuildContext context) {
        return SizedBox(
          width: 20,
          height: 20,
          child: CustomPaint(
            painter: CirclePainter(),
          ),
        );
      }
    

提交回复
热议问题