
issue: https://github.com/flutter/flutter/issues/131784 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
84 lines
2.3 KiB
Dart
84 lines
2.3 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
class _MultiplyPainter extends CustomPainter {
|
|
_MultiplyPainter(this._color);
|
|
|
|
final Color _color;
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
const int xDenominator = 2;
|
|
const int yDenominator = 10;
|
|
final double width = size.width / xDenominator;
|
|
final double height = size.height / yDenominator;
|
|
|
|
for (int y = 0; y < yDenominator; y++) {
|
|
for (int x = 0; x < xDenominator; x++) {
|
|
final Rect rect = Offset(x * width, y * height) & Size(width, height);
|
|
final Paint basePaint = Paint()
|
|
..color = Color.fromARGB(
|
|
(((x + 1) * width) / size.width * 255.0).floor(),
|
|
(((y + 1) * height) / size.height * 255.0).floor(),
|
|
255,
|
|
127);
|
|
canvas.drawRect(rect, basePaint);
|
|
|
|
final Paint multiplyPaint = Paint()
|
|
..color = _color
|
|
..blendMode = BlendMode.multiply;
|
|
canvas.drawRect(rect, multiplyPaint);
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(CustomPainter oldDelegate) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
class AnimatedAdvancedBlend extends StatefulWidget {
|
|
const AnimatedAdvancedBlend({super.key});
|
|
|
|
@override
|
|
State<AnimatedAdvancedBlend> createState() => _AnimatedAdvancedBlendState();
|
|
}
|
|
|
|
class _AnimatedAdvancedBlendState extends State<AnimatedAdvancedBlend> with SingleTickerProviderStateMixin {
|
|
late final AnimationController controller = AnimationController(vsync: this, duration: const Duration(milliseconds: 5000));
|
|
late final Animation<double> animation = controller.drive(Tween<double>(begin: 0.0, end: 1.0));
|
|
Color _color = const Color.fromARGB(255, 255, 0, 255);
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
controller.repeat();
|
|
animation.addListener(() {
|
|
setState(() {
|
|
_color = Color.fromARGB((animation.value * 255).floor(), 255, 0, 255);
|
|
});
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: Scaffold(
|
|
body: CustomPaint(
|
|
painter: _MultiplyPainter(_color),
|
|
child: Container(),
|
|
),
|
|
));
|
|
}
|
|
}
|