geopattern
geopattern copied to clipboard
Having a custom widget
Hello there :)
First of all, I want to thank you for the great work you're doing. So. I have been playing with the library a little bit and as a beginner with CostumPaint, I have found some difficulties to customize the painter as I need. You see the pattern takes the whole screen.. and I don't know how to make it fit only in a custom widget (in my case a Container with specific width and height).. I have tried to implement (Simple example) you're providing as a child to the container, but still, it takes the whole screen.. I know there's a workaround and I'm here asking for help if possible. Best regards and thank you for sharing this amazing library with the community,
10.000 years later...
One way you can achieve this its by using a SizedBox and a Clip, like ClipRRect.
final gen = Random();
final pattern = OverlappingCircles(
radius: 75,
nx: 5,
ny: 5,
fillColors: List.generate(
25,
(int i) => Color.fromARGB(
10 + (gen.nextDouble() * 100).round(),
50 + gen.nextInt(2) * 150,
50 + gen.nextInt(2) * 150,
50 + gen.nextInt(2) * 150)));
SizedBox(
width: 200,
height: 200,
child: ClipRRect(
child: CustomPaint(
painter: FullPainter(
pattern: pattern, background: Colors.black)),
),
)