Skip to content

Commit

Permalink
update old dep special simple_animation
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Sep 11, 2023
1 parent 133b905 commit 1709621
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 55 deletions.
20 changes: 9 additions & 11 deletions lib/widget/animated_background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ enum _ColorTween { color1, color2 }
class AnimatedBackground extends StatelessWidget {
@override
Widget build(BuildContext context) {
final tween = MultiTween<_ColorTween>()
..add(
_ColorTween.color1,
Color(0xffD38312).tweenTo(Colors.lightBlue.shade900),
3.seconds,
)
..add(
final tween = MovieTween()
..tween(_ColorTween.color1,
ColorTween(begin: Color(0xffD38312), end: Colors.lightBlue.shade900),
duration: 3.seconds, curve: Curves.easeIn)
..tween(
_ColorTween.color2,
Color(0xffA83279).tweenTo(Colors.blue.shade600),
3.seconds,
ColorTween(begin: Color(0xffA83279), end: Colors.blue.shade600),
duration: 3.seconds,
);

return MirrorAnimation<MultiTweenValues<_ColorTween>>(
return MirrorAnimationBuilder<Movie>(
tween: tween,
duration: tween.duration,
builder: (context, child, value) {
builder: (context, value, child) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
Expand Down
20 changes: 11 additions & 9 deletions lib/widget/mole_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ class _MoleState extends State<Mole> {

Widget _buildMole() {
_manageParticleLifecycle();
return LoopAnimation<int>(
return LoopAnimationBuilder<int>(
tween: ConstantTween(1),
duration: Duration(seconds: 1),
builder: (context, child, value) {
return Stack(
clipBehavior: Clip.none,
Expand Down Expand Up @@ -98,25 +99,26 @@ class _MoleState extends State<Mole> {
enum _MoleProps { x, y, scale }

class MoleParticle {
late Animatable<MultiTweenValues<_MoleProps>> tween;
late Animatable<Movie> tween;
late Duration startTime;
final duration = 600.milliseconds;

MoleParticle() {
final random = Random();
final x = (100 + 200) * random.nextDouble() * (random.nextBool() ? 1 : -1);
final y = (100 + 200) * random.nextDouble() * (random.nextBool() ? 1 : -1);
double x = (100 + 200) * random.nextDouble() * (random.nextBool() ? 1 : -1);
double y = (100 + 200) * random.nextDouble() * (random.nextBool() ? 1 : -1);

tween = MultiTween<_MoleProps>()
..add(_MoleProps.x, 0.0.tweenTo(x))
..add(_MoleProps.y, 0.0.tweenTo(y))
..add(_MoleProps.scale, 1.0.tweenTo(0.0));
tween = MovieTween()
..tween(_MoleProps.x, Tween(begin: 0.0, end: x), duration: 2.seconds)
..tween(_MoleProps.y, Tween(begin: 0.0, end: y), duration: 2.seconds)
..tween(_MoleProps.scale, Tween(begin: 1.0, end: 0.0),
duration: 2.seconds);

startTime = DateTime.now().duration();
}

Widget buildWidget() {
final MultiTweenValues<_MoleProps> values = tween.transform(progress());
final Movie values = tween.transform(progress());
var alpha = (255 * progress()).toInt();
return Positioned(
left: values.get(_MoleProps.x),
Expand Down
13 changes: 8 additions & 5 deletions lib/widget/particle/particle_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import 'package:flutter/material.dart';
import 'package:simple_animations/simple_animations.dart';
import 'package:supercharged/supercharged.dart';


enum ParticleOffsetProps { x, y }

class ParticleModel {
late MultiTween<ParticleOffsetProps> tween;
late MovieTween tween;
late double size;
late Duration duration;
late Duration startTime;
Expand All @@ -23,9 +22,13 @@ class ParticleModel {
final startPosition = Offset(-0.2 + 1.4 * random.nextDouble(), 1.2);
final endPosition = Offset(-0.2 + 1.4 * random.nextDouble(), -0.2);

tween = MultiTween<ParticleOffsetProps>()
..add(ParticleOffsetProps.x, startPosition.dx.tweenTo(endPosition.dx))
..add(ParticleOffsetProps.y, startPosition.dy.tweenTo(endPosition.dy));
tween = MovieTween()
..tween(ParticleOffsetProps.x,
Tween(begin: startPosition.dx, end: endPosition.dx),
duration: 2.seconds)
..tween(ParticleOffsetProps.y,
Tween(begin: startPosition.dy, end: endPosition.dy),
duration: 2.seconds);

duration = 3000.milliseconds + random.nextInt(6000).milliseconds;
startTime = DateTime.now().duration();
Expand Down
2 changes: 1 addition & 1 deletion lib/widget/particle/particle_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ParticlePainter extends CustomPainter {

particles.forEach((particle) {
final progress = particle.progress();
final MultiTweenValues<ParticleOffsetProps> animation =
final Movie animation =
particle.tween.transform(progress);
final position = Offset(
animation.get<double>(ParticleOffsetProps.x) * size.width,
Expand Down
4 changes: 2 additions & 2 deletions lib/widget/particle/particle_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class _ParticlesWidgetState extends State<ParticlesWidget>

@override
Widget build(BuildContext context) {
return LoopAnimation(
return LoopAnimationBuilder(
tween: ConstantTween(1),
duration: Duration(seconds: 1),
builder: (context, child, dynamic _) {
_simulateParticles();
return CustomPaint(
Expand All @@ -56,5 +57,4 @@ class _ParticlesWidgetState extends State<ParticlesWidget>
particles
.forEach((particle) => particle.checkIfParticleNeedsToBeRestarted());
}

}
32 changes: 8 additions & 24 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ packages:
dependency: "direct main"
description:
name: animations
sha256: "1a5baa987a926607a363522869781637b591735195573ab04006b3f825eef224"
sha256: ef57563eed3620bd5d75ad96189846aca1e033c0c45fc9a7d26e80ab02b88a70
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.3"
version: "2.0.8"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -303,14 +303,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: transitive
description:
name: flutter_lints
sha256: b543301ad291598523947dc534aaddc5aaad597b709d2426d3a0e0d44c5cb493
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
flutter_localizations:
dependency: "direct main"
description: flutter
Expand All @@ -320,10 +312,10 @@ packages:
dependency: "direct main"
description:
name: flutter_markdown
sha256: "453b7ddd0af5bb2f1f83204150de8ec921976dd69960abaa4a32723758692477"
sha256: d4a1cb250c4e059586af0235f32e02882860a508e189b61f2b31b8810c1e1330
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.6.8"
version: "0.6.17+2"
flutter_redux:
dependency: "direct main"
description:
Expand Down Expand Up @@ -537,14 +529,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "6.7.1"
lints:
dependency: transitive
description:
name: lints
sha256: a2c3d198cb5ea2e179926622d433331d8b58374ab8f29cdda6e863bd62fd369c
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.1"
logging:
dependency: transitive
description:
Expand All @@ -557,10 +541,10 @@ packages:
dependency: transitive
description:
name: markdown
sha256: "01512006c8429f604eb10f9848717baeaedf99e991d14a50d540d9beff08e5c6"
sha256: acf35edccc0463a9d7384e437c015a3535772e09714cf60e07eeef3a15870dcd
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.1"
version: "7.1.1"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -941,10 +925,10 @@ packages:
dependency: "direct main"
description:
name: simple_animations
sha256: "79acf025f196001d4680280f67b4d77ca828459b23498606d2fb130a4961046e"
sha256: "1ea7b93fb98e2a611b6865d632de55607b766328d14700143353129ee0559d3a"
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.1"
version: "5.0.2"
sky_engine:
dependency: transitive
description: flutter
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ dependencies:
json_annotation: 4.8.1
package_info_plus: 4.1.0
connectivity_plus: 4.0.2
flutter_markdown: 0.6.8
flutter_markdown: 0.6.17+2
device_info_plus: 9.0.3
url_launcher: 6.1.12
google_fonts: 4.0.4
android_intent_plus: 4.0.2
shared_preferences: 2.0.10
built_value: 8.1.3
simple_animations: 4.0.1
simple_animations: 5.0.2
supercharged: 2.1.1
animations: 2.0.3
animations: 2.0.8
auto_size_text: 3.0.0
flutter_localizations:
sdk: flutter
Expand Down

0 comments on commit 1709621

Please sign in to comment.