From ef875177059a7de213ac540b1649174752c9784e Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 24 Apr 2023 16:26:54 -0600 Subject: [PATCH] arrow rotate and svg usage clean up --- .../sub_widgets/restoring_dialog.dart | 49 ++--------- .../dialogs/claiming_paynym_dialog.dart | 87 ++----------------- .../building_transaction_dialog.dart | 74 ++-------------- .../stack_restore_progress_view.dart | 70 ++++++++------- .../sub_widgets/rescanning_dialog.dart | 18 ++-- .../sub_widgets/wallet_refresh_button.dart | 72 ++++++--------- ...ancelling_transaction_progress_dialog.dart | 46 ++-------- .../animated_widgets/rotate_animation.dart | 64 -------------- .../animated_widgets/rotating_arrows.dart | 87 +++++++++++++++++++ pubspec.yaml | 1 - 10 files changed, 182 insertions(+), 386 deletions(-) delete mode 100644 lib/widgets/animated_widgets/rotate_animation.dart create mode 100644 lib/widgets/animated_widgets/rotating_arrows.dart diff --git a/lib/pages/add_wallet_views/restore_wallet_view/sub_widgets/restoring_dialog.dart b/lib/pages/add_wallet_views/restore_wallet_view/sub_widgets/restoring_dialog.dart index 4836ab885..79cdcd34f 100644 --- a/lib/pages/add_wallet_views/restore_wallet_view/sub_widgets/restoring_dialog.dart +++ b/lib/pages/add_wallet_views/restore_wallet_view/sub_widgets/restoring_dialog.dart @@ -1,9 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flutter_svg/svg.dart'; -import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/util.dart'; +import 'package:stackwallet/widgets/animated_widgets/rotating_arrows.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart'; import 'package:stackwallet/widgets/desktop/secondary_button.dart'; @@ -21,37 +20,15 @@ class RestoringDialog extends StatefulWidget { State createState() => _RestoringDialogState(); } -class _RestoringDialogState extends State - with TickerProviderStateMixin { - late AnimationController? _spinController; - late Animation _spinAnimation; - +class _RestoringDialogState extends State { late final Future Function() onCancel; @override void initState() { onCancel = widget.onCancel; - _spinController = AnimationController( - duration: const Duration(seconds: 2), - vsync: this, - )..repeat(); - - _spinAnimation = CurvedAnimation( - parent: _spinController!, - curve: Curves.linear, - ); - super.initState(); } - @override - void dispose() { - _spinController?.dispose(); - _spinController = null; - - super.dispose(); - } - @override Widget build(BuildContext context) { if (Util.isDesktop) { @@ -69,14 +46,9 @@ class _RestoringDialogState extends State const Spacer( flex: 1, ), - RotationTransition( - turns: _spinAnimation, - child: SvgPicture.asset(Assets.svg.arrowRotate, - width: 40, - height: 40, - color: Theme.of(context) - .extension()! - .accentColorDark), + const RotatingArrows( + width: 40, + height: 40, ), const Spacer( flex: 2, @@ -127,14 +99,9 @@ class _RestoringDialogState extends State child: StackDialog( title: "Restoring wallet", message: "This may take a while. Please do not exit this screen.", - icon: RotationTransition( - turns: _spinAnimation, - child: SvgPicture.asset(Assets.svg.arrowRotate, - width: 24, - height: 24, - color: Theme.of(context) - .extension()! - .accentColorDark), + icon: const RotatingArrows( + width: 24, + height: 24, ), rightButton: TextButton( style: Theme.of(context) diff --git a/lib/pages/paynym/dialogs/claiming_paynym_dialog.dart b/lib/pages/paynym/dialogs/claiming_paynym_dialog.dart index 48093866e..7d42a35d4 100644 --- a/lib/pages/paynym/dialogs/claiming_paynym_dialog.dart +++ b/lib/pages/paynym/dialogs/claiming_paynym_dialog.dart @@ -1,11 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flutter_svg/svg.dart'; -import 'package:lottie/lottie.dart'; -import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/util.dart'; -import 'package:stackwallet/widgets/animated_widgets/rotate_animation.dart'; +import 'package:stackwallet/widgets/animated_widgets/rotating_arrows.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart'; import 'package:stackwallet/widgets/desktop/secondary_button.dart'; @@ -20,40 +17,7 @@ class ClaimingPaynymDialog extends StatefulWidget { State createState() => _RestoringDialogState(); } -class _RestoringDialogState extends State - with TickerProviderStateMixin { - late AnimationController? _spinController; - late Animation _spinAnimation; - late RotateAnimationController? _rotateAnimationController; - - @override - void initState() { - _spinController = AnimationController( - duration: const Duration(seconds: 2), - vsync: this, - )..repeat(); - - _spinAnimation = CurvedAnimation( - parent: _spinController!, - curve: Curves.linear, - ); - - _rotateAnimationController = RotateAnimationController(); - - super.initState(); - } - - @override - void dispose() { - _spinController?.dispose(); - _spinController = null; - - _rotateAnimationController?.forward = null; - _rotateAnimationController?.reset = null; - - super.dispose(); - } - +class _RestoringDialogState extends State { @override Widget build(BuildContext context) { if (Util.isDesktop) { @@ -70,15 +34,9 @@ class _RestoringDialogState extends State ), ], ), - RotationTransition( - turns: _spinAnimation, - child: SvgPicture.asset( - Assets.svg.arrowRotate, - color: - Theme.of(context).extension()!.accentColorDark, - width: 40, - height: 40, - ), + const RotatingArrows( + width: 40, + height: 40, ), Padding( padding: const EdgeInsets.all(40), @@ -123,38 +81,9 @@ class _RestoringDialogState extends State child: StackDialog( title: "Claiming PayNym", message: "We are generating your PayNym", - // icon: RotationTransition( - // turns: _spinAnimation, - // child: SvgPicture.asset( - // Assets.svg.arrowRotate, - // color: - // Theme.of(context).extension()!.accentColorDark, - // width: 24, - // height: 24, - // ), - // ), - icon: RotateAnimation( - lottie: Lottie.asset( - Assets.lottie.arrowRotate, - delegates: LottieDelegates( - values: [ - ValueDelegate.color( - const ["**"], - value: Theme.of(context) - .extension()! - .accentColorDark, - ), - ValueDelegate.strokeColor( - const ["**"], - value: Theme.of(context) - .extension()! - .accentColorDark, - ), - ], - ), - ), - curve: Curves.easeInOutCubic, - controller: _rotateAnimationController, + icon: const RotatingArrows( + width: 24, + height: 24, ), rightButton: SecondaryButton( label: "Cancel", diff --git a/lib/pages/send_view/sub_widgets/building_transaction_dialog.dart b/lib/pages/send_view/sub_widgets/building_transaction_dialog.dart index dc19cfb97..f95fe7bed 100644 --- a/lib/pages/send_view/sub_widgets/building_transaction_dialog.dart +++ b/lib/pages/send_view/sub_widgets/building_transaction_dialog.dart @@ -1,17 +1,14 @@ import 'package:flutter/material.dart'; -import 'package:flutter_svg/svg.dart'; -import 'package:lottie/lottie.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/color_theme.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/util.dart'; +import 'package:stackwallet/widgets/animated_widgets/rotating_arrows.dart'; import 'package:stackwallet/widgets/desktop/secondary_button.dart'; import 'package:stackwallet/widgets/stack_dialog.dart'; -import '../../../widgets/animated_widgets/rotate_animation.dart'; - class BuildingTransactionDialog extends StatefulWidget { const BuildingTransactionDialog({ Key? key, @@ -26,45 +23,16 @@ class BuildingTransactionDialog extends StatefulWidget { State createState() => _RestoringDialogState(); } -class _RestoringDialogState extends State - with TickerProviderStateMixin { - late AnimationController? _spinController; - late Animation _spinAnimation; - - late RotateAnimationController? _rotateAnimationController; - +class _RestoringDialogState extends State { late final VoidCallback onCancel; @override void initState() { onCancel = widget.onCancel; - _spinController = AnimationController( - duration: const Duration(seconds: 2), - vsync: this, - )..repeat(); - - _spinAnimation = CurvedAnimation( - parent: _spinController!, - curve: Curves.linear, - ); - - _rotateAnimationController = RotateAnimationController(); - super.initState(); } - @override - void dispose() { - _spinController?.dispose(); - _spinController = null; - - _rotateAnimationController?.forward = null; - _rotateAnimationController?.reset = null; - - super.dispose(); - } - @override Widget build(BuildContext context) { final isChans = Theme.of(context).extension()!.themeType == @@ -90,28 +58,9 @@ class _RestoringDialogState extends State ), ), if (!isChans) - RotateAnimation( - lottie: Lottie.asset( - Assets.lottie.arrowRotate, - delegates: LottieDelegates( - values: [ - ValueDelegate.color( - const ["**"], - value: Theme.of(context) - .extension()! - .accentColorDark, - ), - ValueDelegate.strokeColor( - const ["**"], - value: Theme.of(context) - .extension()! - .accentColorDark, - ), - ], - ), - ), - curve: Curves.easeInOutCubic, - controller: _rotateAnimationController, + const RotatingArrows( + width: 40, + height: 40, ), const SizedBox( height: 40, @@ -174,16 +123,9 @@ class _RestoringDialogState extends State ) : StackDialog( title: "Generating transaction", - icon: RotationTransition( - turns: _spinAnimation, - child: SvgPicture.asset( - Assets.svg.arrowRotate, - color: Theme.of(context) - .extension()! - .accentColorDark, - width: 24, - height: 24, - ), + icon: const RotatingArrows( + width: 24, + height: 24, ), rightButton: TextButton( style: Theme.of(context) diff --git a/lib/pages/settings_views/global_settings_view/stack_backup_views/sub_views/stack_restore_progress_view.dart b/lib/pages/settings_views/global_settings_view/stack_backup_views/sub_views/stack_restore_progress_view.dart index 9e39443a3..3a286d6d2 100644 --- a/lib/pages/settings_views/global_settings_view/stack_backup_views/sub_views/stack_restore_progress_view.dart +++ b/lib/pages/settings_views/global_settings_view/stack_backup_views/sub_views/stack_restore_progress_view.dart @@ -214,7 +214,7 @@ class _StackRestoreProgressViewState @override void initState() { WidgetsBinding.instance.addPostFrameCallback((_) async { - _restore(); + unawaited(_restore()); }); super.initState(); } @@ -325,7 +325,7 @@ class _StackRestoreProgressViewState : null, ) : RoundedContainer( - padding: EdgeInsets.all(0), + padding: EdgeInsets.zero, color: Theme.of(context) .extension()! .popupBG, @@ -411,7 +411,7 @@ class _StackRestoreProgressViewState : null, ) : RoundedContainer( - padding: EdgeInsets.all(0), + padding: EdgeInsets.zero, color: Theme.of(context) .extension()! .popupBG, @@ -497,7 +497,7 @@ class _StackRestoreProgressViewState : null, ) : RoundedContainer( - padding: EdgeInsets.all(0), + padding: EdgeInsets.zero, color: Theme.of(context) .extension()! .popupBG, @@ -548,44 +548,42 @@ class _StackRestoreProgressViewState final state = ref.watch(stackRestoringUIStateProvider .select((value) => value.trades)); return !isDesktop - ? Container( - child: RestoringItemCard( - left: SizedBox( - width: 32, - height: 32, - child: RoundedContainer( - padding: const EdgeInsets.all(0), - color: Theme.of(context) - .extension()! - .buttonBackSecondary, - child: Center( - child: SvgPicture.asset( - Assets.svg.arrowsTwoWay, - width: 16, - height: 16, - color: Theme.of(context) - .extension()! - .accentColorDark, - ), + ? RestoringItemCard( + left: SizedBox( + width: 32, + height: 32, + child: RoundedContainer( + padding: const EdgeInsets.all(0), + color: Theme.of(context) + .extension()! + .buttonBackSecondary, + child: Center( + child: SvgPicture.asset( + Assets.svg.arrowsTwoWay, + width: 16, + height: 16, + color: Theme.of(context) + .extension()! + .accentColorDark, ), ), ), - right: SizedBox( - width: 20, - height: 20, - child: _getIconForState(state), - ), - title: "Exchange history", - subTitle: state == StackRestoringStatus.failed - ? Text( - "Something went wrong", - style: STextStyles.errorSmall(context), - ) - : null, ), + right: SizedBox( + width: 20, + height: 20, + child: _getIconForState(state), + ), + title: "Exchange history", + subTitle: state == StackRestoringStatus.failed + ? Text( + "Something went wrong", + style: STextStyles.errorSmall(context), + ) + : null, ) : RoundedContainer( - padding: EdgeInsets.all(0), + padding: EdgeInsets.zero, color: Theme.of(context) .extension()! .popupBG, diff --git a/lib/pages/settings_views/wallet_settings_view/wallet_network_settings_view/sub_widgets/rescanning_dialog.dart b/lib/pages/settings_views/wallet_settings_view/wallet_network_settings_view/sub_widgets/rescanning_dialog.dart index c498cbf9a..ac30cb5e7 100644 --- a/lib/pages/settings_views/wallet_settings_view/wallet_network_settings_view/sub_widgets/rescanning_dialog.dart +++ b/lib/pages/settings_views/wallet_settings_view/wallet_network_settings_view/sub_widgets/rescanning_dialog.dart @@ -1,8 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:flutter_svg/svg.dart'; -import 'package:stackwallet/utilities/assets.dart'; -import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/util.dart'; +import 'package:stackwallet/widgets/animated_widgets/rotating_arrows.dart'; import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; import 'package:stackwallet/widgets/stack_dialog.dart'; @@ -66,18 +64,12 @@ class _RescanningDialogState extends State maxWidth: 500, child: child, ), - child: StackDialog( + child: const StackDialog( title: "Rescanning blockchain", message: "This may take a while. Please do not exit this screen.", - icon: RotationTransition( - turns: _spinAnimation, - child: SvgPicture.asset( - Assets.svg.arrowRotate, - width: 24, - height: 24, - color: - Theme.of(context).extension()!.accentColorDark, - ), + icon: RotatingArrows( + width: 24, + height: 24, ), // rightButton: TextButton( // style: Theme.of(context).textButtonTheme.style?.copyWith( diff --git a/lib/pages/wallet_view/sub_widgets/wallet_refresh_button.dart b/lib/pages/wallet_view/sub_widgets/wallet_refresh_button.dart index ac82fc98c..a4b6a34de 100644 --- a/lib/pages/wallet_view/sub_widgets/wallet_refresh_button.dart +++ b/lib/pages/wallet_view/sub_widgets/wallet_refresh_button.dart @@ -3,15 +3,14 @@ import 'dart:async'; import 'package:event_bus/event_bus.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_svg/svg.dart'; import 'package:stackwallet/pages/token_view/token_view.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart'; import 'package:stackwallet/services/event_bus/global_event_bus.dart'; -import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/util.dart'; +import 'package:stackwallet/widgets/animated_widgets/rotating_arrows.dart'; /// [eventBus] should only be set during testing class WalletRefreshButton extends ConsumerStatefulWidget { @@ -36,30 +35,16 @@ class WalletRefreshButton extends ConsumerStatefulWidget { ConsumerState createState() => _RefreshButtonState(); } -class _RefreshButtonState extends ConsumerState - with TickerProviderStateMixin { +class _RefreshButtonState extends ConsumerState { late final EventBus eventBus; - late AnimationController? _spinController; - late Animation _spinAnimation; + late RotatingArrowsController _spinController; late StreamSubscription _syncStatusSubscription; @override void initState() { - _spinController = AnimationController( - duration: const Duration(seconds: 2), - vsync: this, - ); - - _spinAnimation = CurvedAnimation( - parent: _spinController!, - curve: Curves.linear, - ); - - if (widget.initialSyncStatus == WalletSyncStatus.syncing) { - _spinController?.repeat(); - } + _spinController = RotatingArrowsController(); eventBus = widget.eventBus != null ? widget.eventBus! : GlobalEventBus.instance; @@ -71,26 +56,26 @@ class _RefreshButtonState extends ConsumerState widget.tokenContractAddress == null) { switch (event.newStatus) { case WalletSyncStatus.unableToSync: - _spinController?.stop(); + _spinController.stop?.call(); break; case WalletSyncStatus.synced: - _spinController?.stop(); + _spinController.stop?.call(); break; case WalletSyncStatus.syncing: - unawaited(_spinController?.repeat()); + _spinController.repeat?.call(); break; } } else if (widget.tokenContractAddress != null && event.walletId == widget.walletId + widget.tokenContractAddress!) { switch (event.newStatus) { case WalletSyncStatus.unableToSync: - _spinController?.stop(); + _spinController.stop?.call(); break; case WalletSyncStatus.synced: - _spinController?.stop(); + _spinController.stop?.call(); break; case WalletSyncStatus.syncing: - unawaited(_spinController?.repeat()); + _spinController.repeat?.call(); break; } } @@ -102,9 +87,6 @@ class _RefreshButtonState extends ConsumerState @override void dispose() { - _spinController?.dispose(); - _spinController = null; - _syncStatusSubscription.cancel(); super.dispose(); @@ -129,11 +111,11 @@ class _RefreshButtonState extends ConsumerState .getManagerProvider(widget.walletId); final isRefreshing = ref.read(managerProvider).isRefreshing; if (!isRefreshing) { - _spinController?.repeat(); + _spinController.repeat?.call(); ref .read(managerProvider) .refresh() - .then((_) => _spinController?.stop()); + .then((_) => _spinController.stop?.call()); } } else { if (!ref.read(tokenServiceProvider)!.isRefreshing) { @@ -151,22 +133,20 @@ class _RefreshButtonState extends ConsumerState Constants.size.circularBorderRadius, ), ), - child: RotationTransition( - turns: _spinAnimation, - child: SvgPicture.asset( - Assets.svg.arrowRotate, - width: isDesktop ? 12 : 24, - height: isDesktop ? 12 : 24, - color: widget.overrideIconColor != null - ? widget.overrideIconColor! - : isDesktop - ? Theme.of(context) - .extension()! - .textFieldDefaultSearchIconRight - : Theme.of(context) - .extension()! - .textFavoriteCard, - ), + child: RotatingArrows( + spinByDefault: widget.initialSyncStatus == WalletSyncStatus.syncing, + width: isDesktop ? 12 : 24, + height: isDesktop ? 12 : 24, + controller: _spinController, + color: widget.overrideIconColor != null + ? widget.overrideIconColor! + : isDesktop + ? Theme.of(context) + .extension()! + .textFieldDefaultSearchIconRight + : Theme.of(context) + .extension()! + .textFavoriteCard, ), ), ); diff --git a/lib/pages/wallet_view/transaction_views/dialogs/cancelling_transaction_progress_dialog.dart b/lib/pages/wallet_view/transaction_views/dialogs/cancelling_transaction_progress_dialog.dart index ca1e6e7f4..810579e6c 100644 --- a/lib/pages/wallet_view/transaction_views/dialogs/cancelling_transaction_progress_dialog.dart +++ b/lib/pages/wallet_view/transaction_views/dialogs/cancelling_transaction_progress_dialog.dart @@ -1,7 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:flutter_svg/svg.dart'; -import 'package:stackwallet/utilities/assets.dart'; -import 'package:stackwallet/utilities/theme/stack_colors.dart'; +import 'package:stackwallet/widgets/animated_widgets/rotating_arrows.dart'; import 'package:stackwallet/widgets/stack_dialog.dart'; class CancellingTransactionProgressDialog extends StatefulWidget { @@ -13,51 +11,19 @@ class CancellingTransactionProgressDialog extends StatefulWidget { } class _CancellingTransactionProgressDialogState - extends State - with TickerProviderStateMixin { - late AnimationController? _spinController; - late Animation _spinAnimation; - - @override - void initState() { - _spinController = AnimationController( - duration: const Duration(seconds: 2), - vsync: this, - )..repeat(); - - _spinAnimation = CurvedAnimation( - parent: _spinController!, - curve: Curves.linear, - ); - - super.initState(); - } - - @override - void dispose() { - _spinController?.dispose(); - _spinController = null; - - super.dispose(); - } - + extends State { @override Widget build(BuildContext context) { return WillPopScope( onWillPop: () async { return false; }, - child: StackDialog( + child: const StackDialog( title: "Cancelling transaction", message: "This may take a while. Please do not exit this screen.", - icon: RotationTransition( - turns: _spinAnimation, - child: SvgPicture.asset( - Assets.svg.arrowRotate, - width: 24, - height: 24, - color: Theme.of(context).extension()!.accentColorDark, - ), + icon: RotatingArrows( + width: 24, + height: 24, ), // rightButton: TextButton( // style: Theme.of(context).textButtonTheme.style?.copyWith( diff --git a/lib/widgets/animated_widgets/rotate_animation.dart b/lib/widgets/animated_widgets/rotate_animation.dart deleted file mode 100644 index 619a262ab..000000000 --- a/lib/widgets/animated_widgets/rotate_animation.dart +++ /dev/null @@ -1,64 +0,0 @@ -import 'package:flutter/widgets.dart'; - -class RotateAnimationController { - VoidCallback? forward; - VoidCallback? reset; -} - -class RotateAnimation extends StatefulWidget { - const RotateAnimation({ - Key? key, - required this.lottie, - required this.curve, - this.controller, - }) : super(key: key); - - final Widget lottie; - final Curve curve; - final RotateAnimationController? controller; - - @override - State createState() => _RotateAnimationState(); -} - -class _RotateAnimationState extends State - with SingleTickerProviderStateMixin { - late final AnimationController animationController; - late final Animation animation; - late final Duration duration; - - @override - void initState() { - animationController = AnimationController( - vsync: this, - ); - animation = Tween( - begin: 0.0, - ).animate( - CurvedAnimation( - curve: widget.curve, - parent: animationController, - ), - ); - - widget.controller?.forward = animationController.forward; - widget.controller?.reset = animationController.reset; - - super.initState(); - } - - @override - void dispose() { - animationController.dispose(); - widget.controller?.forward = null; - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return RotationTransition( - turns: animation, - child: widget.lottie, - ); - } -} diff --git a/lib/widgets/animated_widgets/rotating_arrows.dart b/lib/widgets/animated_widgets/rotating_arrows.dart new file mode 100644 index 000000000..19edab1c9 --- /dev/null +++ b/lib/widgets/animated_widgets/rotating_arrows.dart @@ -0,0 +1,87 @@ +import 'package:flutter/material.dart'; +import 'package:lottie/lottie.dart'; +import 'package:stackwallet/utilities/assets.dart'; +import 'package:stackwallet/utilities/theme/stack_colors.dart'; + +class RotatingArrowsController { + VoidCallback? forward; + VoidCallback? repeat; + VoidCallback? stop; +} + +class RotatingArrows extends StatefulWidget { + const RotatingArrows({ + Key? key, + required this.height, + required this.width, + this.controller, + this.color, + this.spinByDefault = true, + }) : super(key: key); + + final double height; + final double width; + final RotatingArrowsController? controller; + final Color? color; + final bool spinByDefault; + + @override + State createState() => _RotatingArrowsState(); +} + +class _RotatingArrowsState extends State + with SingleTickerProviderStateMixin { + late final AnimationController animationController; + + @override + void initState() { + animationController = AnimationController(vsync: this); + + widget.controller?.forward = animationController.forward; + widget.controller?.repeat = animationController.repeat; + widget.controller?.stop = animationController.stop; + + super.initState(); + } + + @override + void dispose() { + animationController.dispose(); + widget.controller?.forward = null; + widget.controller?.repeat = null; + widget.controller?.stop = null; + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Lottie.asset( + Assets.lottie.arrowRotate, + controller: animationController, + height: widget.height, + width: widget.width, + delegates: LottieDelegates( + values: [ + ValueDelegate.color( + const ["**"], + value: widget.color ?? + Theme.of(context).extension()!.accentColorDark, + ), + ValueDelegate.strokeColor( + const ["**"], + value: widget.color ?? + Theme.of(context).extension()!.accentColorDark, + ), + ], + ), + onLoaded: (composition) { + animationController.duration = composition.duration; + + // if controller was not set just assume continuous repeat + if (widget.spinByDefault) { + animationController.repeat(); + } + }, + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index aef5af5bb..550969665 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -248,7 +248,6 @@ flutter: - assets/svg/chevron-up.svg - assets/svg/lock-keyhole.svg - assets/svg/lock-open.svg - - assets/svg/rotate-exclamation.svg - assets/svg/folder-down.svg - assets/svg/network-wired.svg - assets/svg/network-wired-2.svg