Created
October 25, 2019 13:46
-
-
Save av/f27a4bed6c05bf04dcc3c370da8eefd6 to your computer and use it in GitHub Desktop.
Flutter: magic, particle Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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()); | |
/// | |
/// // 10 randomly sized fading circles | |
/// ParticleGenerator(10, (i) => FadingCircle(radius: Randoms.rnd.nextDouble() * 10)); | |
/// | |
/// // 5 small and 5 large fading circles | |
/// ParticleGenerator(10, (i) => FadingCircle(radius: i < 5 ? 10 : 20)); | |
/// ``` | |
class ParticleGenerator extends Particle with CompositeParticle { | |
List<Particle> children; | |
ParticleGenerator( | |
int count, | |
ParticleProvider generator, | |
) { | |
this.children = List<Particle>.generate(count, generator); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment