Skip to content

Instantly share code, notes, and snippets.

View av's full-sized avatar
💻
🌚

Ivan Charapanau av

💻
🌚
View GitHub Profile
@av
av / main.dart
Created October 25, 2019 13:51
Flutter: magic, circles
/// Just a container for parameters
/// allowing to draw a circle on a [Canvas] later
class CircleParameters {
double radius;
Offset offset;
CircleParameters({@required this.radius, @required this.offset});
}
/// Renders certain amount of circles on a [Canvas],
@av
av / main.dart
Created October 25, 2019 13:48
Flutter: magic, fading circle color
class FadingCircle extends Particle with Fading {
final double radius;
final Color color;
FadingCircle({
this.radius = 10,
this.color = Colors.white,
});
@override
@av
av / main.dart
Created October 25, 2019 13:46
Flutter: magic, particle Generator
/// A function which returns [Particle] when called
typedef ParticleProvider = Particle Function(int i);
/// A [CompositeParticle] which allows to use [ParticleProvider]
/// generator functions as source for children particles
///
/// ```dart
/// // 10 plain fading circles
/// ParticleGenerator(10, (i) => FadingCircle());
///
@av
av / main.dart
Created October 25, 2019 12:30
Flutter: magic, scaled fading circles
// In OutlineButton.build > Particles > Aligned
// ...
child: Burst(
children: List<Particle>.generate(
20,
(i) => ScalingParticle(
child: FadingCircle(radius: Randoms.rnd.nextDouble() * 8 + 2),
from: .2,
to: 1.5,
),
@av
av / main.dart
Created October 25, 2019 11:47
Flutter: magic, curved burst
// in Burst constructor, children.map(...)
// ...
(particle) => CurvedParticle(
curve: Interval(
// Interval would start at random point from 0 to 0.5
// and finish at random point between 0.6 and 1.0
Randoms.rnd.nextDouble() * .5,
Randoms.rnd.nextDouble() * .4 + .6,
),
child: MovingParticle(
@av
av / main.dart
Created October 25, 2019 11:45
Flutter: magic, curvedParticle
class CurvedParticle extends Particle with NestedParticle, Curved {
Curve curve;
Particle child;
CurvedParticle({
@required this.curve,
@required this.child,
});
}
@av
av / main.dart
Created October 25, 2019 11:45
Flutter: magic, curvedParticle
class CurvedParticle extends Particle with NestedParticle, Curved {
Curve curve;
Particle child;
CurvedParticle({
@required this.curve,
@required this.child,
});
}
@av
av / main.dart
Created October 25, 2019 11:43
Flutter: magic, curved behavior
mixin Curved on Updatable {
Curve curve;
@override
void update(Animation animation) {
super.update(
CurveTween(curve: curve).animate(animation),
);
}
}
@av
av / main.dart
Created October 25, 2019 10:42
Flutter: magic, eased particles
class Particles extends StatefulWidget {
final Duration duration;
final Particle particle;
final ParticlesWidgetBuilder builder;
// New property you defined to make animation
// easing configurable from outside
final Curve curve;
const Particles({
@av
av / main.dart
Created October 25, 2019 10:05
Flutter: magic, fading circle random radius
// In OutlineButton.build > Particles > Aligned > FadingCircle
// ...
radius: Randoms.rnd.nextDouble() * 10
// ...