1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'dart:math' show cos, sin;
6import 'dart:typed_data';
7
8import 'package:flutter/material.dart';
9
10class RRectBlur extends StatefulWidget {
11 const RRectBlur({super.key});
12
13 @override
14 State<RRectBlur> createState() => _RRectBlurPageState();
15}
16
17class _RRectBlurPageState extends State<RRectBlur> with SingleTickerProviderStateMixin {
18 late final AnimationController controller;
19 double tick = 0.0;
20
21 @override
22 void initState() {
23 super.initState();
24 controller = AnimationController(vsync: this, duration: const Duration(hours: 1));
25 controller.addListener(() {
26 setState(() {
27 tick += 1;
28 });
29 });
30 controller.forward(from: 0);
31 }
32
33 @override
34 void dispose() {
35 controller.dispose();
36 super.dispose();
37 }
38
39 @override
40 Widget build(BuildContext context) {
41 return CustomPaint(
42 size: const Size(500, 500),
43 painter: PointsPainter(tick),
44 child: Container(),
45 );
46 }
47}
48
49class PointsPainter extends CustomPainter {
50 PointsPainter(this.tick);
51
52 final double tick;
53
54 final Float32List data = Float32List(8000);
55
56 static const List<Color> kColors = <Color>[
57 Colors.red,
58 Colors.blue,
59 Colors.green,
60 Colors.yellow,
61 Colors.orange,
62 Colors.purple,
63 Colors.pink,
64 Colors.deepPurple,
65 ];
66
67 @override
68 void paint(Canvas canvas, Size size) {
69 if (size.width == 0) {
70 return;
71 }
72 final double halfHeight = size.height / 2.0;
73 const double freq = 0.25;
74 const int circleCount = 40;
75 for (int i = 0; i < circleCount; ++i) {
76 final double radius = 25 * cos(i + (1.0 * 2.0 * 3.1415 * tick) / 60.0) + 25;
77 final Paint paint =
78 Paint()
79 ..style = PaintingStyle.fill
80 ..filterQuality = FilterQuality.low
81 ..maskFilter = MaskFilter.blur(BlurStyle.normal, radius);
82 final double yval = halfHeight * sin(i + (freq * 2.0 * 3.1415 * tick) / 60.0) + halfHeight;
83 final double xval = (i.toDouble() / circleCount) * size.width;
84 canvas.drawCircle(Offset(xval, yval), 50, paint..color = kColors[i % kColors.length]);
85 }
86 }
87
88 @override
89 bool shouldRepaint(covariant CustomPainter oldDelegate) {
90 return true;
91 }
92}
93

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com