Skip to content

Instantly share code, notes, and snippets.

@felixblaschke
Created March 5, 2021 22:18
Show Gist options
  • Save felixblaschke/4d6d1367b16bf0b30348ff4e4410b66c to your computer and use it in GitHub Desktop.
Save felixblaschke/4d6d1367b16bf0b30348ff4e4410b66c to your computer and use it in GitHub Desktop.
Particle blendmode
import 'package:flutter/material.dart';
import 'package:simple_animations/simple_animations.dart';
/*
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
flutter:
sdk: flutter
simple_animations: ^3.0.0-nullsafety.4
*/
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: LoopAnimation( // Loop to see FPS
duration: Duration(seconds: 1),
tween: ConstantTween(1),
builder: (context, _, value) {
return Container(
child: CustomPaint(
painter: MyPainter(),
),
);
}),
),
),
);
}
}
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
..color = Colors.red
..maskFilter = MaskFilter.blur(BlurStyle.normal, 100)
..blendMode = BlendMode.darken;
for (var i = 0; i < 100; i++) {
canvas.drawRect(Rect.fromLTWH(5.0 * i % 100, 5.0 * i, 100, 100), paint);
}
}
@override
bool shouldRepaint(covariant MyPainter oldDelegate) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment