1

In my flutter application, I would like to make a circle as a background like that: ViewPort

nvoigt
  • 75,013
  • 26
  • 93
  • 142
ungarmichael
  • 101
  • 1
  • 9
  • Nice idea. What's keeping you from doing it? – nvoigt Jul 01 '20 at 14:01
  • Does this answer your question? [Flutter mask a circle into a container](https://stackoverflow.com/questions/53639066/flutter-mask-a-circle-into-a-container) – nvoigt Jul 01 '20 at 14:24

1 Answers1

1

The problem is mainly when the screen is in landscape, you can't fit a circle there unless it covers all the screen. There's another approach with ClipRect, let me know if this doesn't work with you.


class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    return LayoutBuilder(
      builder: (context, constraints) {
        final radius = constraints.biggest.width * 1.2;
        
        return SizedBox(
          width: radius,
          height: radius,
          child: FittedBox(
            fit: BoxFit.fitHeight,
            child: Container(
              width: radius,
              height: radius ,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                color: Colors.blue,
              ),
            ),
          ),
        );
      }
    );
  }
}

Another approach:


class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    return LayoutBuilder(
      builder: (context, constraints) {
        final radius = constraints.biggest.width * 1.2;
        
        return OverflowBox(
          maxWidth: radius,
          maxHeight: radius,
          child: Container(
            width: radius,
            height: radius ,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: Colors.blue,
            ),
          ),
        );
      }
    );
  }
}

final radius = constraints.biggest.width * 1.2;: The 1.2 is how much the circle is overlapping, you can change this number.

Ahmed Erabti
  • 306
  • 1
  • 5