简体   繁体   中英

How to create random circles on flutter? circles should not be overlapping with each other

I would like to create something similar to below given photo in the flutter. This is the output I need in flutter. Circles should not be overlapping with each other. Below given code just gives one circle but i need multiple with random placements.

REFERENCE OUTPUT

  Container(
            width: 28,
            height: 28,
            decoration: BoxDecoration(
              color: Colors.green.withOpacity(0.25), // border color
              shape: BoxShape.circle,
            ),
            child: Padding(
              padding: EdgeInsets.all(2), // border width
              child: Container( // or ClipRRect if you need to clip the content
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  color: Colors.blue, // inner circle color
                ),
                child: Container(), // inner content
              ),
            ),
          ),

You would have to generate circles with centers placed at random locations, and random radiuses; for each added circle, you would have to check if it overlaps with existing circles, by calculating the cartesian distance among the centers: if that distance is greater than the sum of the radiuses of the two circles being compared, then those two didn't overlap.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM