| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cake_wallet/src/widgets/cake_image_widget.dart'; |
| 3 | import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; |
| 4 | import 'package:flutter/material.dart'; |
| 5 | import 'package:flutter_mobx/flutter_mobx.dart'; |
| 6 | import 'package:flutter_svg/svg.dart'; |
| 7 | |
| 8 | class ChainIcon extends StatelessWidget { |
| 9 | const ChainIcon( |
| 10 | {super.key, |
| 11 | required this.iconPath, |
| 12 | required this.dashboardViewModel, |
| 13 | required this.isSyncHeavy, |
| 14 | required this.showSyncedMessage}); |
| 15 | |
| 16 | final String iconPath; |
| 17 | final bool isSyncHeavy; |
| 18 | final DashboardViewModel dashboardViewModel; |
| 19 | final bool showSyncedMessage; |
| 20 | |
| 21 | @override |
| 22 | Widget build(BuildContext context) { |
| 23 | return Observer( |
| 24 | builder: (_) { |
| 25 | final progress = dashboardViewModel.status.progress(); |
| 26 | final done = !showSyncedMessage && (!isSyncHeavy || progress >= 1); |
| 27 | |
| 28 | return Stack( |
| 29 | children: [ |
| 30 | AnimatedOpacity( |
| 31 | duration: Duration(milliseconds: 100), |
| 32 | opacity: done ? 0 : 1, |
| 33 | // Faded out means "nothing to report", so it must leave the tree too. |
| 34 | child: ExcludeSemantics( |
| 35 | excluding: done || showSyncedMessage, |
| 36 | child: CircularProgressIndicator( |
| 37 | value: progress, |
| 38 | color: showSyncedMessage ? Color(0xFFFF12A439) : Color(0xFFFFB84E), |
| 39 | strokeWidth: 2, |
| 40 | semanticsLabel: S.of(context).synchronizing, |
| 41 | semanticsValue: "${(progress * 100).round()}%", |
| 42 | ), |
| 43 | ), |
| 44 | ), |
| 45 | AnimatedScale( |
| 46 | duration: Duration(milliseconds: 150), |
| 47 | scale: done ? 1 : 0.8, |
| 48 | child: AnimatedSwitcher( |
| 49 | duration: Duration(milliseconds: 150), |
| 50 | child: CakeImageWidget( |
| 51 | imageUrl: iconPath, |
| 52 | key: ValueKey(progress >= 1), |
| 53 | width: 36, |
| 54 | height: 36, |
| 55 | colorFilter: ColorFilter.mode( |
| 56 | done |
| 57 | ? Theme.of(context).colorScheme.primary.withOpacity(0.2) |
| 58 | : Theme.of(context).colorScheme.primary, |
| 59 | BlendMode.srcIn, |
| 60 | ), |
| 61 | ), |
| 62 | ), |
| 63 | ), |
| 64 | ], |
| 65 | ); |
| 66 | }, |
| 67 | ); |
| 68 | } |
| 69 | } |