Flutter Circle Design

后端 未结 5 2044
旧巷少年郎
旧巷少年郎 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 02:49

    Try This!

    I have added 5 circles you can add more. And instead of RaisedButton use InkResponse.

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(new MaterialApp(home: new ExampleWidget()));
    }
    
    class ExampleWidget extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        Widget bigCircle = new Container(
          width: 300.0,
          height: 300.0,
          decoration: new BoxDecoration(
            color: Colors.orange,
            shape: BoxShape.circle,
          ),
        );
    
        return new Material(
          color: Colors.black,
          child: new Center(
            child: new Stack(
              children: <Widget>[
                bigCircle,
                new Positioned(
                  child: new CircleButton(onTap: () => print("Cool"), iconData: Icons.favorite_border),
                  top: 10.0,
                  left: 130.0,
                ),
                new Positioned(
                  child: new CircleButton(onTap: () => print("Cool"), iconData: Icons.timer),
                  top: 120.0,
                  left: 10.0,
                ),
                new Positioned(
                  child: new CircleButton(onTap: () => print("Cool"), iconData: Icons.place),
                  top: 120.0,
                  right: 10.0,
                ),
                new Positioned(
                  child: new CircleButton(onTap: () => print("Cool"), iconData: Icons.local_pizza),
                  top: 240.0,
                  left: 130.0,
                ),
                new Positioned(
                  child: new CircleButton(onTap: () => print("Cool"), iconData: Icons.satellite),
                  top: 120.0,
                  left: 130.0,
                ),
              ],
            ),
          ),
        );
      }
    }
    
    class CircleButton extends StatelessWidget {
      final GestureTapCallback onTap;
      final IconData iconData;
    
      const CircleButton({Key key, this.onTap, this.iconData}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        double size = 50.0;
    
        return new InkResponse(
          onTap: onTap,
          child: new Container(
            width: size,
            height: size,
            decoration: new BoxDecoration(
              color: Colors.white,
              shape: BoxShape.circle,
            ),
            child: new Icon(
              iconData,
              color: Colors.black,
            ),
          ),
        );
      }
    }
    
    0 讨论(0)
  • 2021-01-31 02:49

    You can use CustomMultiChildLayout to draw this kind of layouts. Here you can find a tutorial: How to Create Custom Layout Widgets in Flutter.

    0 讨论(0)
  • 2021-01-31 02:56

    you can use decoration like this :

       Container(
                        width: 60,
                        height: 60,
                        child: Icon(CustomIcons.option, size: 20,),
                        decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            color: Color(0xFFe0f2f1)),
                      )
    

    Now you have circle shape and Icon on it.

    0 讨论(0)
  • 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(),
          ),
        );
      }
    
    0 讨论(0)
  • 2021-01-31 03:06

    I would use a https://docs.flutter.io/flutter/widgets/Stack-class.html to be able to freely position widgets.

    To create circles

      new BoxDecoration(
        color: effectiveBackgroundColor,
        image: backgroundImage != null
          ? new DecorationImage(image: backgroundImage, fit: BoxFit.cover)
          : null,
        shape: BoxShape.circle,
      ),
    

    and https://docs.flutter.io/flutter/widgets/Transform/Transform.rotate.html to position the white dots.

    0 讨论(0)
提交回复
热议问题