From 56695e361a5fa93d2de1809e57858528b875a0bd Mon Sep 17 00:00:00 2001 From: Edouard Marquez Date: Mon, 17 Jul 2023 14:09:41 +0200 Subject: [PATCH] Now with a better animation --- .../lib/pages/hunger_games/congrats.dart | 134 ++++-------------- packages/smooth_app/macos/Podfile.lock | 8 +- 2 files changed, 29 insertions(+), 113 deletions(-) diff --git a/packages/smooth_app/lib/pages/hunger_games/congrats.dart b/packages/smooth_app/lib/pages/hunger_games/congrats.dart index 68e3a447dd6..c2483874e36 100644 --- a/packages/smooth_app/lib/pages/hunger_games/congrats.dart +++ b/packages/smooth_app/lib/pages/hunger_games/congrats.dart @@ -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 { @@ -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: [ const Padding( - padding: EdgeInsets.only(top: SMALL_SPACE), + padding: EdgeInsetsDirectional.only(top: SMALL_SPACE), child: _Header(), ), FractionallySizedBox( @@ -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 _star1; - late AnimationController _controller2; - late Animation _star2; - late AnimationController _controller3; - late Animation _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(begin: 0.0, end: 1.0).animate(_controller1); - - _controller2 = AnimationController( - vsync: this, - duration: const Duration(seconds: 1), - ); - _star2 = Tween(begin: 0.0, end: 1.0).animate(_controller2); - - _controller3 = AnimationController( - vsync: this, - duration: const Duration(seconds: 1), - ); - _star3 = Tween(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, @@ -218,51 +169,24 @@ class _HeaderState extends State<_Header> with TickerProviderStateMixin { excludeSemantics: true, child: Column( children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - 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: ['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, @@ -272,12 +196,4 @@ class _HeaderState extends State<_Header> with TickerProviderStateMixin { ), ); } - - @override - void dispose() { - _controller1.dispose(); - _controller2.dispose(); - _controller3.dispose(); - super.dispose(); - } } diff --git a/packages/smooth_app/macos/Podfile.lock b/packages/smooth_app/macos/Podfile.lock index 31cce45a894..9712cc6f4ce 100644 --- a/packages/smooth_app/macos/Podfile.lock +++ b/packages/smooth_app/macos/Podfile.lock @@ -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