Skip to content

Commit

Permalink
Now with a better animation
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k committed Jul 22, 2023
1 parent 4197331 commit 56695e3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 113 deletions.
134 changes: 25 additions & 109 deletions packages/smooth_app/lib/pages/hunger_games/congrats.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:lottie/lottie.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:rive/rive.dart';
import 'package:smooth_app/data_models/user_management_provider.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_simple_button.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/generic_lib/duration_constants.dart';
import 'package:smooth_app/generic_lib/loading_dialog.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/helpers/app_helper.dart';
import 'package:smooth_app/pages/user_management/login_page.dart';

class CongratsWidget extends StatelessWidget {
Expand All @@ -34,13 +34,15 @@ class CongratsWidget extends StatelessWidget {
child: SmoothCard(
ignoreDefaultSemantics: true,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: MEDIUM_SPACE),
padding: const EdgeInsetsDirectional.symmetric(
horizontal: MEDIUM_SPACE,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Padding(
padding: EdgeInsets.only(top: SMALL_SPACE),
padding: EdgeInsetsDirectional.only(top: SMALL_SPACE),
child: _Header(),
),
FractionallySizedBox(
Expand Down Expand Up @@ -151,65 +153,14 @@ class CongratsWidget extends StatelessWidget {
}
}

class _Header extends StatefulWidget {
class _Header extends StatelessWidget {
const _Header();

@override
State<_Header> createState() => _HeaderState();
}

class _HeaderState extends State<_Header> with TickerProviderStateMixin {
late AnimationController _controller1;
late Animation<double> _star1;
late AnimationController _controller2;
late Animation<double> _star2;
late AnimationController _controller3;
late Animation<double> _star3;

@override
void initState() {
super.initState();
// We create a custom animation, to add a slight delay between each
// apparition of a star

_controller1 = AnimationController(
vsync: this,
duration: const Duration(seconds: 1),
);
_star1 = Tween<double>(begin: 0.0, end: 1.0).animate(_controller1);

_controller2 = AnimationController(
vsync: this,
duration: const Duration(seconds: 1),
);
_star2 = Tween<double>(begin: 0.0, end: 1.0).animate(_controller2);

_controller3 = AnimationController(
vsync: this,
duration: const Duration(seconds: 1),
);
_star3 = Tween<double>(begin: 0.0, end: 1.0).animate(_controller3);

_controller1.addListener(() {
if (!_controller2.isAnimating && _controller1.value > 0.25) {
_controller2.repeat();
setState(() {});
}
});

_controller2.addListener(() {
if (!_controller3.isAnimating && _controller2.value > 0.25) {
_controller3.repeat();
setState(() {});
}
});

_controller1.repeat();
}

@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final double multiplier =
math.min(350, MediaQuery.of(context).size.height * 0.3) / 235;

return Semantics(
enabled: true,
Expand All @@ -218,51 +169,24 @@ class _HeaderState extends State<_Header> with TickerProviderStateMixin {
excludeSemantics: true,
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Transform.scale(
scale: 2.0,
child: Lottie.asset(
'assets/animations/stars.json',
controller: _star1,
package: AppHelper.APP_PACKAGE,
height: 70.0,
width: 70.0,
),
),
AnimatedOpacity(
opacity: _controller2.isAnimating ? 1.0 : 0.0,
duration: SmoothAnimationsDuration.short,
child: Transform.scale(
scale: 2.0,
child: Lottie.asset(
'assets/animations/stars.json',
controller: _star2,
package: AppHelper.APP_PACKAGE,
height: 70.0,
width: 70.0,
),
),
),
AnimatedOpacity(
opacity: _controller3.isAnimating ? 1.0 : 0.0,
duration: SmoothAnimationsDuration.short,
child: Transform.scale(
scale: 2.0,
child: Lottie.asset(
'assets/animations/stars.json',
controller: _star3,
package: AppHelper.APP_PACKAGE,
height: 70.0,
width: 70.0,
),
),
Padding(
padding: const EdgeInsetsDirectional.symmetric(
vertical: SMALL_SPACE,
),
child: SizedBox(
width: 230 * multiplier,
height: 235 * multiplier,
child: const RiveAnimation.asset(
'assets/animations/off.riv',
artboard: 'Success',
stateMachines: <String>['Animation'],
),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: MEDIUM_SPACE),
padding: const EdgeInsetsDirectional.symmetric(
vertical: MEDIUM_SPACE,
),
child: Text(
appLocalizations.thanks_for_contributing,
style: Theme.of(context).textTheme.titleLarge,
Expand All @@ -272,12 +196,4 @@ class _HeaderState extends State<_Header> with TickerProviderStateMixin {
),
);
}

@override
void dispose() {
_controller1.dispose();
_controller2.dispose();
_controller3.dispose();
super.dispose();
}
}
8 changes: 4 additions & 4 deletions packages/smooth_app/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
audioplayers_darwin: dcad41de4fbd0099cb3749f7ab3b0cb8f70b810c
device_info_plus: 5401765fde0b8d062a2f8eb65510fb17e77cf07f
file_selector_macos: 0f85c1108e2fd597b58246bc0b0c1cb483d7593b
file_selector_macos: 468fb6b81fac7c0e88d71317f3eec34c3b008ff9
flutter_secure_storage_macos: 6ceee8fbc7f484553ad17f79361b556259df89aa
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
in_app_review: a850789fad746e89bce03d4aeee8078b45a53fd0
mobile_scanner: ed7618fb749adc6574563e053f3b8e5002c13994
package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce
path_provider_foundation: eaf5b3e458fc0e5fbb9940fb09980e853fe058b8
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
rive_common: acedcab7802c0ece4b0d838b71d7deb637e1309a
Sentry: 4c9babff9034785067c896fd580b1f7de44da020
sentry_flutter: 1346a880b24c0240807b53b10cf50ddad40f504e
share_plus: 76dd39142738f7a68dd57b05093b5e8193f220f7
shared_preferences_foundation: e2dae3258e06f44cc55f49d42024fd8dd03c590c
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
sqflite: a5789cceda41d54d23f31d6de539d65bb14100ea
url_launcher_macos: 5335912b679c073563f29d89d33d10d459f95451
url_launcher_macos: d2691c7dd33ed713bf3544850a623080ec693d95

PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7

Expand Down

0 comments on commit 56695e3

Please sign in to comment.