forked from CarGuo/gsy_github_app_flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
223 additions
and
64 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:simple_animations/simple_animations/controlled_animation.dart'; | ||
import 'package:simple_animations/simple_animations/multi_track_tween.dart'; | ||
|
||
class AnimatedBackground extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
final tween = MultiTrackTween([ | ||
Track("color1").add(Duration(seconds: 3), | ||
ColorTween(begin: Color(0xffD38312), end: Colors.lightBlue.shade900)), | ||
Track("color2").add(Duration(seconds: 3), | ||
ColorTween(begin: Color(0xffA83279), end: Colors.blue.shade600)) | ||
]); | ||
|
||
return ControlledAnimation( | ||
playback: Playback.MIRROR, | ||
tween: tween, | ||
duration: tween.duration, | ||
builder: (context, animation) { | ||
return Container( | ||
decoration: BoxDecoration( | ||
gradient: LinearGradient( | ||
begin: Alignment.topCenter, | ||
end: Alignment.bottomCenter, | ||
colors: [animation["color1"], animation["color2"]])), | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:simple_animations/simple_animations/animation_progress.dart'; | ||
import 'package:simple_animations/simple_animations/multi_track_tween.dart'; | ||
|
||
class ParticleModel { | ||
Animatable tween; | ||
double size; | ||
AnimationProgress animationProgress; | ||
Random random; | ||
int defaultMilliseconds; | ||
|
||
ParticleModel(this.random, {this.defaultMilliseconds = 500}) { | ||
restart(); | ||
} | ||
|
||
restart({Duration time = Duration.zero}) { | ||
final startPosition = Offset(-0.2 + 1.4 * random.nextDouble(), 1.2); | ||
|
||
final endPosition = Offset(-0.2 + 1.4 * random.nextDouble(), -0.2); | ||
|
||
final duration = | ||
Duration(milliseconds: defaultMilliseconds + random.nextInt(1000)); | ||
|
||
tween = MultiTrackTween([ | ||
Track("x").add( | ||
duration, Tween(begin: startPosition.dx, end: endPosition.dx), | ||
curve: Curves.easeInOutSine), | ||
Track("y").add( | ||
duration, Tween(begin: startPosition.dy, end: endPosition.dy), | ||
curve: Curves.easeIn), | ||
]); | ||
animationProgress = AnimationProgress(duration: duration, startTime: time); | ||
size = 0.2 + random.nextDouble() * 0.4; | ||
} | ||
|
||
maintainRestart(Duration time) { | ||
if (animationProgress.progress(time) == 1.0) { | ||
restart(time: time); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:gsy_github_app_flutter/widget/particle/particle_model.dart'; | ||
|
||
class ParticlePainter extends CustomPainter { | ||
List<ParticleModel> particles; | ||
Duration time; | ||
Color color; | ||
|
||
ParticlePainter(this.particles, this.time, {this.color = Colors.white}); | ||
|
||
@override | ||
void paint(Canvas canvas, Size size) { | ||
final paint = Paint()..color = color.withAlpha(50); | ||
particles.forEach((particle) { | ||
var progress = particle.animationProgress.progress(time); | ||
final animation = particle.tween.transform(progress); | ||
final position = | ||
Offset(animation["x"] * size.width, animation["y"] * size.height); | ||
canvas.drawCircle(position, size.width * 0.2 * particle.size, paint); | ||
}); | ||
} | ||
|
||
@override | ||
bool shouldRepaint(CustomPainter oldDelegate) => true; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:gsy_github_app_flutter/widget/particle/particle_model.dart'; | ||
import 'package:gsy_github_app_flutter/widget/particle/particle_painter.dart'; | ||
import 'package:simple_animations/simple_animations/rendering.dart'; | ||
|
||
class ParticlesWidget extends StatefulWidget { | ||
final int numberOfParticles; | ||
|
||
ParticlesWidget(this.numberOfParticles); | ||
|
||
@override | ||
_ParticlesWidgetState createState() => _ParticlesWidgetState(); | ||
} | ||
|
||
class _ParticlesWidgetState extends State<ParticlesWidget> { | ||
final Random random = Random(); | ||
|
||
final List<ParticleModel> particles = []; | ||
|
||
@override | ||
void initState() { | ||
List.generate(widget.numberOfParticles, (index) { | ||
particles.add(ParticleModel(random, defaultMilliseconds: 2000)); | ||
}); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Rendering( | ||
startTime: Duration(seconds: 50), | ||
onTick: _simulateParticles, | ||
builder: (context, time) { | ||
_simulateParticles(time); | ||
return CustomPaint( | ||
painter: ParticlePainter(particles, time), | ||
); | ||
}, | ||
); | ||
} | ||
|
||
_simulateParticles(Duration time) { | ||
particles.forEach((particle) => particle.maintainRestart(time)); | ||
} | ||
} |
This file contains 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
This file contains 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